-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathWrongWarp.cs
98 lines (85 loc) · 3.79 KB
/
WrongWarp.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System.Linq;
using OcaBase;
using System.Runtime.CompilerServices;
namespace OcaBase
{
public partial class WrongWarp
{
#region Helper Classes
public class Params
{
public int BaseEntranceIndex { get { return _BaseEntranceIndex; } }
int _BaseEntranceIndex;
public int CutsceneIndex { get { return _CutsceneOffset; } }
int _CutsceneOffset;
public Params(int baseEntrance, int cutscene)
{
_BaseEntranceIndex = baseEntrance;
_CutsceneOffset = cutscene;
}
}
#endregion
/// <summary>
/// Returns the calculation of a wrong warp as a WrongWarp.Result object
/// </summary>
/// <param name="wwp">The parameters for the wrong warp calculation</param>
/// <param name="wrongWarp">The returned result</param>
/// <returns>True if the operation can be performed, false otherwise</returns>
public static bool GetResult(WrongWarp.Params wwp, out WrongWarp.Result wrongWarp)
{
bool result;
result = GetResults(wwp, out wrongWarp);
if (result)
wrongWarp.SetResult();
return result;
}
private static bool GetResults(WrongWarp.Params wwp, out WrongWarp.Result wrongWarp)
{
int finalEntranceIndex; //the destination entrance index after calculation
//initialize our WrongWarp.Result
wrongWarp = new WrongWarp.Result(wwp);
//Test to see if the baseEntranceIndex is a valid entrance, and collect information on it
//if the cutscene offset is not between 0 and 15, or we can't retrieve an entrance index table record
//report that the operation can't be performed
if ((wwp.CutsceneIndex < 0 || wwp.CutsceneIndex > 16)
|| !Queries.TryGetEntranceByIndex(wwp.BaseEntranceIndex, out wrongWarp.Start))
{
return false;
}
//baseEntranceIndex exists, so calculate our finalEntranceIndex
finalEntranceIndex = wrongWarp.Start.Index.BaseIndex + wwp.CutsceneIndex + 4;
//if the final index is off the table, don't calculate the final entrance point.
if (finalEntranceIndex > 0x613)
{
wrongWarp.ValidEntranceTableRecord = false;
return true;
}
//now retrieve the record at finalEntranceIndex
if (Queries.TryGetEntranceByIndex(finalEntranceIndex, out wrongWarp.End))
{
if (Scene.TryGetSingle(wrongWarp.End.Index.SceneId, out wrongWarp.FinalScene))
{
//we've got our base and final entrance indexes
//now to determine if the scene defines the final entrance correctly
GetFinalEntrance(wrongWarp, wwp.CutsceneIndex);
return true;
}
}
return false;
}
/// <summary>
/// Sets the WrongWarp.Result's resultant entrance data
/// </summary>
/// <param name="wrongWarp">the WrongWarp.Result being generated</param>
/// <param name="cutsceneOffset">the cutscene offset of the wrong warp</param>
/// <returns></returns>
private static void GetFinalEntrance(WrongWarp.Result wrongWarp, int cutsceneOffset)
{
OcarinaDataContext db = new OcarinaDataContext();
wrongWarp.FinalEntrance = db.Entrances.SingleOrDefault(ent =>
ent.SceneId == wrongWarp.FinalScene.ID
&& ent.Setup == ((wrongWarp.FinalScene.x18) ? cutsceneOffset + 4 : 0)
&& ent.EntranceNum == wrongWarp.End.Index.EntranceNum);
}
}
}