using System; using System.Collections.Generic; namespace ET { [FriendClass(typeof(Unit))] [FriendClass(typeof(Construct))] public class C2M_CheatHandler: AMActorLocationRpcHandler { 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(); 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(); 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; } } }