You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
4.3 KiB
121 lines
4.3 KiB
using System; |
|
using System.Collections.Generic; |
|
|
|
namespace ET |
|
{ |
|
[FriendClass(typeof(Unit))] |
|
[FriendClass(typeof(Construct))] |
|
public class C2M_CheatHandler: AMActorLocationRpcHandler<Unit, C2M_Cheat, M2C_Cheat> |
|
{ |
|
protected override async ETTask Run(Unit unit, C2M_Cheat request, M2C_Cheat response, Action reply) |
|
{ |
|
try |
|
{ |
|
|
|
Log.Info($"{request.Num},{request.Id},{request.Type}"); |
|
if (request.Type == 1) |
|
{ |
|
StoreComponent storeComponent = unit.GetComponent<StoreComponent>(); |
|
if (request.Num >= 0) |
|
{ |
|
storeComponent.Add(request.Id, request.Num); |
|
} |
|
else |
|
{ |
|
storeComponent.Remove(request.Id, (int)Math.Abs(request.Num)); |
|
} |
|
} |
|
else if (request.Type == 2) |
|
{ |
|
if (request.Id == NumericType.Water) |
|
{ |
|
unit.Water += request.Num; |
|
} |
|
else if (request.Id == NumericType.Food) |
|
{ |
|
unit.Food += request.Num; |
|
} |
|
else if (request.Id == NumericType.SilverTael) |
|
{ |
|
if (request.Num >= 0) |
|
{ |
|
unit.SilverTael += (int) Math.Abs(request.Num); |
|
} |
|
else |
|
{ |
|
unit.SilverTael -= (int) Math.Abs(request.Num); |
|
} |
|
} |
|
else if (request.Id == NumericType.GoldIngot) |
|
{ |
|
if (request.Num >= 0) |
|
{ |
|
unit.GoldIngot += (int) Math.Abs(request.Num); |
|
} |
|
else |
|
{ |
|
unit.GoldIngot -= (int) Math.Abs(request.Num); |
|
} |
|
} |
|
else if (request.Id == NumericType.Season) |
|
{ |
|
if (request.Num >= 0) |
|
{ |
|
unit.Season += (int) Math.Abs(request.Num); |
|
} |
|
else |
|
{ |
|
unit.Season -= (int) Math.Abs(request.Num); |
|
} |
|
} |
|
else if (request.Id == NumericType.Scale) |
|
{ |
|
if (request.Num >= 0) |
|
{ |
|
unit.Scale += (int) Math.Abs(request.Num); |
|
} |
|
else |
|
{ |
|
unit.Scale -= (int) Math.Abs(request.Num); |
|
} |
|
} |
|
else if (request.Id == NumericType.Prosperity) |
|
{ |
|
if (request.Num >= 0) |
|
{ |
|
unit.Prosperity += (int) Math.Abs(request.Num); |
|
} |
|
else |
|
{ |
|
unit.Prosperity -= (int) Math.Abs(request.Num); |
|
} |
|
} |
|
else if (request.Id == NumericType.Time) |
|
{ |
|
unit.GameTime = (int) request.Num; |
|
} |
|
} |
|
else if (request.Type == 3) |
|
{ |
|
ConstructComponent cc = unit.GetComponent<ConstructComponent>(); |
|
foreach (var v in cc.Children.Values) |
|
{ |
|
var construct = ((Construct) v); |
|
construct.Progress = construct.Config.BodyVolume; |
|
} |
|
} |
|
|
|
response.Error = ErrorCode.ERR_Success; |
|
reply(); |
|
} |
|
catch (Exception e) |
|
{ |
|
response.Message = e.ToString(); |
|
response.Error = ErrorCode.ERR_OperateFail; |
|
reply(); |
|
} |
|
|
|
await ETTask.CompletedTask; |
|
} |
|
} |
|
} |