Skip to content

Commit 10209e1

Browse files
author
CSDotNET
committed
fixed replay issue,
some arg got better
1 parent 31f419d commit 10209e1

File tree

4 files changed

+103
-91
lines changed

4 files changed

+103
-91
lines changed

TetrEnvironment/Environment.cs

+57-45
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ namespace TetrEnvironment;
99

1010
public class Environment
1111
{
12+
#region Enum
13+
14+
public enum GameModeEnum
15+
{
16+
SelfControl,
17+
Normal,
18+
EventBased
19+
}
20+
21+
#endregion
22+
1223
#region Infos
1324

1425
public GarbageInfo GarbageInfo { get; private set; }
@@ -29,7 +40,7 @@ public class Environment
2940
private readonly GameType? _gameType;
3041
private readonly Environment _manager;
3142
private ServiceProvider _provider;
32-
private readonly EventFullData _eventFull;
43+
private readonly EventFullOptionsData _eventFullOptions;
3344

3445
#endregion
3546

@@ -44,10 +55,10 @@ public int CurrentFrame
4455
public string? Username { get; private set; }
4556
public bool[] PressingKeys { get; private set; }
4657
public int TotalFrame { get; private set; }
47-
public bool IsSelfControlMode { get; private set; }
58+
public readonly GameModeEnum GameMode;
4859
public GameData GameData { get; private set; }
4960
public CustomStats CustomStats { get; private set; }
50-
internal readonly KicksetBase Kickset;
61+
public KicksetBase Kickset { get; private set; }
5162

5263
#endregion
5364

@@ -61,11 +72,9 @@ public int CurrentFrame
6172
/// <exception cref="Exception"></exception>
6273
public Environment(IReadOnlyList<Event>? events, GameType? gametype)
6374
{
64-
IsSelfControlMode = false;
75+
GameMode = GameModeEnum.Normal;
6576
_manager = this;
6677
_events = events;
67-
//todo:implement it in Options
68-
Kickset = new KicksetSRSPlus();
6978

7079
if (events != null &&
7180
events.FirstOrDefault(@event => @event.type == EventType.End) is EventEnd eventEnd)
@@ -75,33 +84,39 @@ public Environment(IReadOnlyList<Event>? events, GameType? gametype)
7584

7685
try
7786
{
78-
_eventFull = (events.First(@event => @event.type == EventType.Full) as EventFull).data;
87+
_eventFullOptions = (events.First(@event => @event.type == EventType.Full) as EventFull).data.options;
7988
}
8089
catch (Exception e)
8190
{
8291
throw new Exception(
83-
"some of games in this replay has no FULL event! it will be ignored in TETR.IO. please consider to remove spetific game.");
92+
"some of games in this replay has no Full event! it will be ignored in TETR.IO. please consider to remove spetific game.");
8493
}
8594

8695
_gameType = gametype;
8796
Reset();
8897

89-
Username = _eventFull.options.username;
98+
Username = _eventFullOptions.username;
9099
}
91100

92101
/// <summary>
93102
/// for self control
94103
/// </summary>
95-
/// <param name="fullData"></param>
96-
public Environment(EventFullData fullData)
104+
/// <param name="fullOptionsData"></param>
105+
public Environment(EventFullOptionsData fullOptionsData)
97106
{
98-
IsSelfControlMode = true;
107+
GameMode = GameModeEnum.SelfControl;
99108
TotalFrame = -1;
100109
_manager = this;
101-
_eventFull = fullData;
110+
_eventFullOptions = fullOptionsData;
102111
Reset();
103112
}
104113

114+
public Environment(EventFullOptions options)
115+
{
116+
GameMode = GameModeEnum.EventBased;
117+
_manager = this;
118+
}
119+
105120
private void SolveWithDI(ServiceProvider provider)
106121
{
107122
GarbageInfo = provider.GetService<GarbageInfo>() ?? throw new InvalidOperationException();
@@ -116,7 +131,7 @@ private void SolveWithDI(ServiceProvider provider)
116131
LineInfo = provider.GetService<LineInfo>() ?? throw new InvalidOperationException();
117132
}
118133

119-
private void InitDI(EventFullData fullData, ref ServiceProvider provider)
134+
private void InitDI(EventFullOptionsData fullDataOptions, ref ServiceProvider provider)
120135
{
121136
ServiceCollection service = new ServiceCollection();
122137
service.AddSingleton<BagInfo>();
@@ -134,65 +149,57 @@ private void InitDI(EventFullData fullData, ref ServiceProvider provider)
134149
service.AddSingleton<Options>();
135150
service.AddSingleton<Stats>();
136151
service.AddSingleton<LineInfo>();
137-
service.AddSingleton<EventFullData>(fullData);
152+
service.AddSingleton<EventFullOptionsData>(fullDataOptions);
138153
service.AddSingleton<Environment>(this);
139154
service.AddSingleton<Handling>(new Handling()
140155
{
141-
ARR = fullData.options.handling.arr ?? 5,
142-
DAS = fullData.options.handling.das ?? 12,
143-
SDF = fullData.options.handling.sdf ?? 20,
144-
DCD = fullData.options.handling.dcd ?? 20,
145-
Cancel = fullData.options.handling.cancel ?? false,
146-
SafeLock = fullData.options.handling.safelock == true ? 1 : 0,
156+
ARR = fullDataOptions.handling.arr ?? 5,
157+
DAS = fullDataOptions.handling.das ?? 12,
158+
SDF = fullDataOptions.handling.sdf ?? 20,
159+
DCD = fullDataOptions.handling.dcd ?? 20,
160+
Cancel = fullDataOptions.handling.cancel ?? false,
161+
SafeLock = fullDataOptions.handling.safelock == true ? 1 : 0,
147162
});
148163

149164
#if DEBUG
150-
if (fullData.options?.handling?.arr == null)
165+
if (fullDataOptions.handling?.arr == null)
151166
Debug.WriteLine("options.handling is initialized by default. it is wrong in most case.");
152167
#endif
153168

154169
provider = service.BuildServiceProvider();
155170
}
156171

157-
172+
/// <summary>
173+
/// for normal
174+
/// </summary>
175+
/// <returns></returns>
176+
/// <exception cref="Exception"></exception>
158177
public bool NextFrame()
159178
{
179+
if (GameMode != GameModeEnum.Normal)
180+
throw new Exception("This NextFrame function is for normal.");
181+
182+
160183
if (_manager.FrameInfo.CurrentFrame > TotalFrame)
161184
return false;
162185

163186
GameData.SubFrame = 0;
164187
_manager.FrameInfo.PullEvents(_events);
165188
CurrentFrame++;
166189

167-
_manager.HandleInfo.ProcessShift(false, 1 - GameData.SubFrame);
168-
_manager.FallInfo.FallEvent(null, 1 - GameData.SubFrame);
169-
_manager.WaitingFrameInfo.ExcuteWaitingFrames();
170-
171-
//unsafe waiting
172-
173-
if (_manager.GameData.Options.GravityIncrease > 0 &&
174-
CurrentFrame > _manager.GameData.Options.GravityMargin)
175-
_manager.GameData.Gravity += _manager.GameData.Options.GravityIncrease / 60;
176-
177-
if (_manager.GameData.Options.GarbageIncrease > 0 &&
178-
CurrentFrame > _manager.GameData.Options.GarbageMargin)
179-
_manager.GameData.Options.GarbageMultiplier += _manager.GameData.Options.GarbageIncrease / 60;
180-
181-
if (_manager.GameData.Options.GarbageCapIncrease > 0)
182-
_manager.GameData.Options.GarbageCap += _manager.GameData.Options.GarbageCapIncrease / 60;
183-
190+
InternalNextFrame();
184191

185192
return true;
186193
}
187194

188195
/// <summary>
189-
/// for self control
196+
/// for self control or event-based
190197
/// </summary>
191198
/// <param name="event"></param>
192199
public void NextFrame(Queue<Event> events)
193200
{
194-
if (!IsSelfControlMode)
195-
throw new Exception("This NextFrame is for self control, please consider using normal NextFrame.");
201+
if (GameMode is GameModeEnum.EventBased or GameModeEnum.SelfControl)
202+
throw new Exception("This NextFrame function is for self control or event-based.");
196203

197204
GameData.SubFrame = 0;
198205

@@ -203,7 +210,12 @@ public void NextFrame(Queue<Event> events)
203210
}
204211

205212
CurrentFrame++;
213+
InternalNextFrame();
214+
}
206215

216+
217+
private void InternalNextFrame()
218+
{
207219
_manager.HandleInfo.ProcessShift(false, 1 - GameData.SubFrame);
208220
_manager.FallInfo.FallEvent(null, 1 - GameData.SubFrame);
209221
_manager.WaitingFrameInfo.ExcuteWaitingFrames();
@@ -220,10 +232,10 @@ public void NextFrame(Queue<Event> events)
220232
_manager.GameData.Options.GarbageCap += _manager.GameData.Options.GarbageCapIncrease / 60;
221233
}
222234

223-
224235
public void Reset()
225236
{
226-
InitDI(_eventFull, ref _provider);
237+
Kickset = new KicksetSRSPlus();
238+
InitDI(_eventFullOptions, ref _provider);
227239
SolveWithDI(_provider);
228240
GameData = new GameData();
229241
GameData.Initialize(_provider, _gameType);

TetrEnvironment/GameData.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ public void Initialize(ServiceProvider provider,GameType? gametype)
2727
HoldLocked = false;
2828

2929
//next rng
30-
var eventFull = provider.GetService<EventFullData>();
30+
var eventFullData = provider.GetService<EventFullOptionsData>();
3131
Rng = new Rng();
32-
Rng.Init(eventFull.options.seed);
32+
Rng.Init(eventFullData.seed);
3333
provider.GetService<Environment>().BagInfo.PopulateBag();
34-
if (eventFull.options.no_szo == true && Bag.Count != 0)
34+
if (eventFullData.no_szo == true && Bag.Count != 0)
3535
{
3636
for (int i = 0;
3737
i < Bag.Count && (Bag.Peek() is Tetromino.MinoType.S or Tetromino.MinoType.Z or Tetromino.MinoType.O);

TetrEnvironment/Info/FallInfo.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void Lock(bool emptyDrop = false)
153153
_manager.GameData.Stats.PiecesPlaced++;
154154

155155
if (!emptyDrop && _manager.GameData.Handling.SafeLock != 0)
156-
_manager.GameData.Handling.SafeLock = 7;
156+
_manager.GameData.Falling.SafeLock = 7;
157157

158158
var lines = _manager.LineInfo.ClearLines();
159159
var are = lines != 0 ? _manager.GameData.Options.LineClearAre : _manager.GameData.Options.Are;

TetrEnvironment/Options.cs

+42-42
Original file line numberDiff line numberDiff line change
@@ -51,50 +51,50 @@ public class Options
5151

5252
public bool ClipListenIDs { get; internal set; }
5353

54-
public Options(EventFullData fullData)
54+
public Options(EventFullOptionsData fullOptionsData)
5555
{
56-
Levels = fullData.options.levels ?? false;
57-
GBase = fullData.options.gbase ?? 0.65;
58-
GSpeed = fullData.options.gspeed ?? 0.007;
59-
LevelSpeed = fullData.options.levelspeed ?? 0.42;
60-
MasterLevels = fullData.options.masterlevels ?? false;
56+
Levels = fullOptionsData.levels ?? false;
57+
GBase = fullOptionsData.gbase ?? 0.65;
58+
GSpeed = fullOptionsData.gspeed ?? 0.007;
59+
LevelSpeed = fullOptionsData.levelspeed ?? 0.42;
60+
MasterLevels = fullOptionsData.masterlevels ?? false;
6161

62-
Version = fullData.options.version;
63-
GravityIncrease = fullData.options.gincrease ?? 0;
64-
GravityMargin = fullData.options.gmargin ?? 0;
65-
Gravity = fullData.options.g ?? 0;
66-
GarbageIncrease = fullData.options.garbageincrease ?? 0;
67-
GarbageMargin = fullData.options.garbagemargin ?? 0;
68-
GarbageMultiplier = fullData.options.garbagemultiplier ?? 1;
69-
GarbageCapIncrease = fullData.options.garbagecapincrease ?? 0;
70-
GarbageCap = fullData.options.garbagecap ?? 8;
71-
InfiniteMovement = fullData.options.infinitemovement ?? false;
72-
InfiniteHold = fullData.options.infinitehold ?? false;
73-
LockResets = fullData.options.lockresets ?? 15;
74-
Allow180 = fullData.options.allow180 ?? true;
75-
AllowHardDrop = fullData.options.allow_harddrop ?? true;
76-
DisplayHold = fullData.options.display_hold ?? true;
77-
LockTime = fullData.options.locktime ?? 30;
78-
SpinBonuses = fullData.options.spinbonuses ?? SpinBonusesType.TSpins;
79-
ComboTable = fullData.options.combotable ?? ComboTableType.Multiplier;
80-
BTBChaining = fullData.options.btbchaining ?? true;
81-
GarbageTargetBonus = fullData.options.garbagetargetbonus ?? GarbageTargetBonusType.None;
82-
GarbageAttackCap = fullData.options.garbageattackcap ?? false;
83-
GarbageBlocking = fullData.options.garbageblocking ?? GarbageBlockingType.ComboBlocking;
84-
Passthrough = fullData.options.passthrough ?? PassthroughType.Limited;
85-
GarbageSpeed = fullData.options.garbagespeed ?? 20;
86-
BagType = fullData.options.bagtype ?? BagType.Bag7;
87-
GarbagePhase = (fullData.options.garbagephase as int?) ?? 0;
88-
GarbageQueue = fullData.options.garbagequeue ?? false;
89-
GarbageHoleSize = fullData.options.garbageholesize ?? 1;
90-
AllClears = fullData.options.allclears ?? true;
91-
LineClearAre = fullData.options.lineclear_are ?? 0;
92-
Are = fullData.options.are ?? 0;
93-
GarbageEntry = fullData.options.garbageentry ?? GarbageEntryType.Instant;
94-
GarbageAre = (int)(Math.Max(1, fullData.options.garbageare ?? 5));
95-
Shielded = fullData.options.shielded ?? false;
96-
HasGarbage = fullData.options.hasgarbage ?? true;
97-
GarbageCapMax = fullData.options.garbagecapmax ?? 40;
62+
Version = fullOptionsData.version;
63+
GravityIncrease = fullOptionsData.gincrease ?? 0;
64+
GravityMargin = fullOptionsData.gmargin ?? 0;
65+
Gravity = fullOptionsData.g ?? 0;
66+
GarbageIncrease = fullOptionsData.garbageincrease ?? 0;
67+
GarbageMargin = fullOptionsData.garbagemargin ?? 0;
68+
GarbageMultiplier = fullOptionsData.garbagemultiplier ?? 1;
69+
GarbageCapIncrease = fullOptionsData.garbagecapincrease ?? 0;
70+
GarbageCap = fullOptionsData.garbagecap ?? 8;
71+
InfiniteMovement = fullOptionsData.infinitemovement ?? false;
72+
InfiniteHold = fullOptionsData.infinitehold ?? false;
73+
LockResets = fullOptionsData.lockresets ?? 15;
74+
Allow180 = fullOptionsData.allow180 ?? true;
75+
AllowHardDrop = fullOptionsData.allow_harddrop ?? true;
76+
DisplayHold = fullOptionsData.display_hold ?? true;
77+
LockTime = fullOptionsData.locktime ?? 30;
78+
SpinBonuses = fullOptionsData.spinbonuses ?? SpinBonusesType.TSpins;
79+
ComboTable = fullOptionsData.combotable ?? ComboTableType.Multiplier;
80+
BTBChaining = fullOptionsData.btbchaining ?? true;
81+
GarbageTargetBonus = fullOptionsData.garbagetargetbonus ?? GarbageTargetBonusType.None;
82+
GarbageAttackCap = fullOptionsData.garbageattackcap ?? false;
83+
GarbageBlocking = fullOptionsData.garbageblocking ?? GarbageBlockingType.ComboBlocking;
84+
Passthrough = fullOptionsData.passthrough ?? PassthroughType.Limited;
85+
GarbageSpeed = fullOptionsData.garbagespeed ?? 20;
86+
BagType = fullOptionsData.bagtype ?? BagType.Bag7;
87+
GarbagePhase = (fullOptionsData.garbagephase as int?) ?? 0;
88+
GarbageQueue = fullOptionsData.garbagequeue ?? false;
89+
GarbageHoleSize = fullOptionsData.garbageholesize ?? 1;
90+
AllClears = fullOptionsData.allclears ?? true;
91+
LineClearAre = fullOptionsData.lineclear_are ?? 0;
92+
Are = fullOptionsData.are ?? 0;
93+
GarbageEntry = fullOptionsData.garbageentry ?? GarbageEntryType.Instant;
94+
GarbageAre = (int)(Math.Max(1, fullOptionsData.garbageare ?? 5));
95+
Shielded = fullOptionsData.shielded ?? false;
96+
HasGarbage = fullOptionsData.hasgarbage ?? true;
97+
GarbageCapMax = fullOptionsData.garbagecapmax ?? 40;
9898
ClipListenIDs = true;
9999
}
100100
}

0 commit comments

Comments
 (0)