forked from E-riCA0/StawdewValley
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNPCController.cs
More file actions
157 lines (148 loc) · 4.38 KB
/
NPCController.cs
File metadata and controls
157 lines (148 loc) · 4.38 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Decompiled with JetBrains decompiler
// Type: StardewValley.NPCController
// Assembly: Stardew Valley, Version=1.2.6400.27469, Culture=neutral, PublicKeyToken=null
// MVID: 77B7094A-F6F0-4ACC-91F4-E335E2733EDB
// Assembly location: D:\SteamLibrary\steamapps\common\Stardew Valley\Stardew Valley.exe
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
namespace StardewValley
{
public class NPCController
{
private int pauseTime = -1;
public NPC puppet;
private bool loop;
private List<Vector2> path;
private Vector2 target;
private int pathIndex;
private int speed;
private NPCController.endBehavior behaviorAtEnd;
private int CurrentPathX
{
get
{
if (this.pathIndex >= this.path.Count)
return 0;
return (int) this.path[this.pathIndex].X;
}
}
private int CurrentPathY
{
get
{
if (this.pathIndex >= this.path.Count)
return 0;
return (int) this.path[this.pathIndex].Y;
}
}
private bool MovingHorizontally
{
get
{
return (uint) this.CurrentPathX > 0U;
}
}
public NPCController(NPC n, List<Vector2> path, bool loop, NPCController.endBehavior endBehavior = null)
{
if (n == null)
return;
this.speed = n.speed;
this.loop = loop;
this.puppet = n;
this.path = path;
this.setMoving(true);
this.behaviorAtEnd = endBehavior;
}
private bool setMoving(bool newTarget)
{
if (this.puppet == null || this.pathIndex >= this.path.Count)
return false;
int direction = 2;
if (this.CurrentPathX > 0)
direction = 1;
else if (this.CurrentPathX < 0)
direction = 3;
else if (this.CurrentPathY < 0)
direction = 0;
else if (this.CurrentPathY > 0)
direction = 2;
this.puppet.Halt();
this.puppet.faceDirection(direction);
if (this.CurrentPathX != 0 && this.CurrentPathY != 0)
{
this.pauseTime = this.CurrentPathY;
this.puppet.faceDirection(this.CurrentPathX % 4);
return true;
}
this.puppet.setMovingInFacingDirection();
if (newTarget)
this.target = new Vector2(this.puppet.position.X + (float) (this.CurrentPathX * Game1.tileSize), this.puppet.Position.Y + (float) (this.CurrentPathY * Game1.tileSize));
return true;
}
public bool update(GameTime time, GameLocation location, List<NPCController> allControllers)
{
this.puppet.speed = this.speed;
bool flag = false;
foreach (NPCController allController in allControllers)
{
if (allController.puppet != null)
{
if (allController.puppet.Equals((object) this.puppet))
flag = true;
if (allController.puppet.facingDirection == this.puppet.facingDirection && !allController.puppet.Equals((object) this.puppet) && allController.puppet.GetBoundingBox().Intersects(this.puppet.nextPosition(this.puppet.facingDirection)))
{
if (!flag)
return false;
break;
}
}
}
this.puppet.MovePosition(time, Game1.viewport, location);
if (this.pauseTime < 0 && !this.puppet.isMoving())
this.setMoving(false);
if (this.pauseTime < 0 && (double) Math.Abs(Vector2.Distance(this.puppet.position, this.target)) <= (double) this.puppet.Speed)
{
this.pathIndex = this.pathIndex + 1;
if (!this.setMoving(true))
{
if (this.loop)
{
this.pathIndex = 0;
this.setMoving(true);
}
else
{
if (this.behaviorAtEnd != null)
this.behaviorAtEnd();
return true;
}
}
}
else if (this.pauseTime >= 0)
{
this.pauseTime = this.pauseTime - time.ElapsedGameTime.Milliseconds;
if (this.pauseTime < 0)
{
this.pathIndex = this.pathIndex + 1;
if (!this.setMoving(true))
{
if (this.loop)
{
this.pathIndex = 0;
this.setMoving(true);
}
else
{
if (this.behaviorAtEnd != null)
this.behaviorAtEnd();
return true;
}
}
}
}
return false;
}
public delegate void endBehavior();
}
}