/// <summary> /// Добавляем из наших вещей в сделку /// </summary> private void AddThingListApply() { if (!EditOrderIsMy || AddThingGrid.DataSource == null) { return; } //выбранное в AddThingGrid.DataSource, где кол-во выбранного в поле CountToTransfer foreach (var item in AddThingGrid.DataSource) { if (item.CountToTransfer == 0) { continue; } var th = ThingTrade.CreateTrade(item.AnyThing, item.CountToTransfer); EditOrder.SellThings.Add(th); } EditOrderChange(); AddThingGrid = null; }
private void EditOrderShowBuyThings(ref Rect rect) { for (int i = 0; i < EditOrder.BuyThings.Count; i++) { //это редактирование получаемых вещей. Тут все поля либо также только чтение либо все редактируемые var th = EditOrder.BuyThings[i]; var xl = 0f; var xr = 0f; //иконка var rect3 = new Rect(rect.x, rect.y, 24f, 24f); xl = rect.x + 24f * 2f; if (th.Concrete) { GameUtils.DravLineThing(rect3, th.DataThing, true); } else { GameUtils.DravLineThing(rect3, th, true, Color.gray); } //"x" перед кол-во var textCntW = Text.CalcSize("* x").x; rect3 = new Rect(xl, rect.y, textCntW, 24f); xl += textCntW; Text.Anchor = TextAnchor.MiddleRight; Widgets.Label(rect3, th.Concrete ? "* x" : "x"); Text.Anchor = TextAnchor.MiddleLeft; if (th.Concrete) { TooltipHandler.TipRegion(rect3, "OCity_Dialog_Exchenge_Specific_Facility_Assigned".Translate()); } //кол-во Count rect3 = new Rect(xl, rect.y, 50f, 24f); xl += 50f; if (EditOrderIsMy) { int countToTransfer = th.Count; string editBuffer; if (!EditOrderEditBuffer.TryGetValue(th.GetHashCode(), out editBuffer)) { EditOrderEditBuffer.Add(th.GetHashCode(), editBuffer = countToTransfer.ToString()); } Widgets.TextFieldNumeric <int>(rect3.ContractedBy(2f), ref countToTransfer, ref editBuffer, 0f, 999999999f); EditOrderEditBuffer[th.GetHashCode()] = editBuffer; if (countToTransfer > 0 && th.Count != countToTransfer) { th.Count = countToTransfer; EditOrderChange(); } } else { Widgets.Label(rect3, th.Count.ToString()); } //множитель кол-во повторов textCntW = 40f; Text.Anchor = TextAnchor.MiddleLeft; rect3 = new Rect(xl, rect.y, textCntW, 15f); GUI.color = Color.gray; Widgets.Label(rect3, "*" + EditOrder.CountReady.ToString()); rect3 = new Rect(xl, rect.y + 12f, textCntW, 15f); GUI.color = Color.white; Widgets.Label(rect3, "=" + (EditOrder.CountReady * th.Count).ToString()); xl += textCntW; //далее всё в обратном порядке справа-налево //крестик убрать строку xr = rect.xMax - 24f; rect3 = new Rect(xr, rect.y, 24f, 24f); if (EditOrderIsMy && Widgets.ButtonImage(rect3, IconDelTex)) { EditOrder.BuyThings.RemoveAt(i--); } //с трупа WornByCorpse, прочность HitPoints из MaxHitPoints и качество Quality EditOrderShowHitAndQ(ref rect, ref xr, th); //название rect3 = new Rect(xl, rect.y, xr - xl, 24f); Widgets.Label(rect3, th.Name); rect.y += 24f; } if (EditOrderIsMy) { var rect4 = new Rect(rect); rect4.width = 150f; if (Widgets.ButtonText(rect4.ContractedBy(1f) , "OCity_Dialog_Exchenge_Add".Translate() , true, false, true)) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); var formm = new Dialog_SelectThingDef(); formm.ClearFilter(); formm.PostCloseAction = () => { if (formm.SelectThingDef == null) { return; } var th = ThingTrade.CreateTrade(formm.SelectThingDef, formm.SelectHitPointsPercents.min, formm.SelectQualities.min, 1); EditOrder.BuyThings.Add(th); EditOrderChange(); }; Find.WindowStack.Add(formm); return; } rect.y += 24f; } }
/// <summary> /// область снизу справа - просмотр и редактирование ордера /// </summary> /// <param name="inRect"></param> public void DoWindowEditOrder(Rect inRect) { if (PlaceCurrent == null) { PlaceCurrent = new Place(); WorldObject wo; if (PlaceMap != null) { wo = PlaceMap.info.parent; } else { wo = PlaceCaravan; } PlaceCurrent.Name = wo.LabelCap; PlaceCurrent.PlaceServerId = UpdateWorldController.GetServerInfo(wo).ServerId; PlaceCurrent.ServerName = SessionClientController.My.ServerName; PlaceCurrent.Tile = wo.Tile; PlaceCurrent.DayPath = 0; } if (EditOrder == null) { //Действие не выбрано: по умолчанию настраиваем панельна создание нового ордера EditOrderTitle = "OCity_Dialog_Exchenge_Order_Create".Translate(); var editOrder = new OrderTrade(); editOrder.Owner = SessionClientController.My; editOrder.Place = PlaceCurrent; editOrder.CountBeginMax = 1; editOrder.SellThings = new List <ThingTrade>(); editOrder.BuyThings = new List <ThingTrade>(); var silverDef = (ThingDef)GenDefDatabase.GetDef(typeof(ThingDef), "Silver"); var th = ThingTrade.CreateTrade(silverDef, 0f, QualityCategory.Awful, 1); editOrder.BuyThings.Add(th); editOrder.PrivatPlayers = new List <Player>(); SetEditOrder(editOrder); } bool existInServer = EditOrder.Id != 0; //заголовок Rect rect = new Rect(0f, 0f, inRect.width, 18); inRect.yMin += rect.height; Text.Font = GameFont.Tiny; // высота Tiny 18 Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(rect, EditOrderTitle); ///todo ///полоску проскрутки //кнопка в углу rect = new Rect(inRect.width - 150f, 20f, 150f, 24); if (!EditOrderToTrade) { GUI.color = Color.red; } if (Widgets.ButtonText(rect.ContractedBy(1f) , EditOrderIsMy ? existInServer ? "OCity_Dialog_Exchenge_Save".Translate() : "OCity_Dialog_Exchenge_Create".Translate() : "OCity_Dialog_Exchenge_Trade".Translate() , true, false, true)) { GUI.color = Color.white; SoundDefOf.Tick_High.PlayOneShotOnCamera(null); if (!EditOrderToTrade) { return; } if (!EditOrderIsMy) { //торговать //todo } else { //создать или отредактировать SessionClientController.Command((connect) => { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); if (!connect.ExchengeEdit(EditOrder)) { Loger.Log("Client ExchengeEdit error: " + connect.ErrorMessage); Find.WindowStack.Add(new Dialog_Input("OCity_Dialog_Exchenge_Action_Not_CarriedOut".Translate(), connect.ErrorMessage, true)); } else { SetEditOrder(null); } UpdateOrders(); }); return; } EditOrderChange(); return; } GUI.color = Color.white; //кнопка if (!EditOrderIsMy) { rect = new Rect(160f, 20f, inRect.width - 160f - 160f, 24); if (Widgets.ButtonText(rect.ContractedBy(1f) , "OCity_Dialog_Exchenge_Counterproposal".Translate() , true, false, true)) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); //todo return; } } if (EditOrderIsMy && existInServer && EditOrder.Id != 0) { rect = new Rect(160f, 20f, 100f, 24); if (Widgets.ButtonText(rect.ContractedBy(1f) , "OCity_Dialog_Exchenge_Delete".Translate() , true, false, true)) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); SessionClientController.Command((connect) => { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); EditOrder.Id = -EditOrder.Id; if (!connect.ExchengeEdit(EditOrder)) { EditOrder.Id = -EditOrder.Id; Loger.Log("Client ExchengeEdit error: " + connect.ErrorMessage); Find.WindowStack.Add(new Dialog_Input("OCity_Dialog_Exchenge_Action_Not_CarriedOut".Translate(), connect.ErrorMessage, true)); } else { SetEditOrder(null); } UpdateOrders(); }); return; } } rect = new Rect(0, 20f, 150f, 24f); if (Widgets.ButtonText(rect.ContractedBy(1f) , "OCity_Dialog_Exchenge_Order_New".Translate() , true, false, true)) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); SetEditOrder(null); return; } inRect.yMin += rect.height; rect = new Rect(0f, 44f, inRect.width, 24f); Text.Anchor = TextAnchor.MiddleLeft; if (EditOrderIsMy) { Widgets.Label(rect, "OCity_Dialog_Exchenge_No_Exchanges".Translate()); var rect2 = new Rect(rect.x + 250f, rect.y, 70f, rect.height); int countToTransfer = EditOrder.CountBeginMax; string editBuffer; if (!EditOrderEditBuffer.TryGetValue(EditOrder.GetHashCode(), out editBuffer)) { EditOrderEditBuffer.Add(EditOrder.GetHashCode(), editBuffer = countToTransfer.ToString()); } Widgets.TextFieldNumeric <int>(rect2.ContractedBy(2f), ref countToTransfer, ref editBuffer, 1f, 999999999f); EditOrderEditBuffer[EditOrder.GetHashCode()] = editBuffer; if (countToTransfer > 0) { EditOrder.CountBeginMax = countToTransfer; EditOrderChange(); } rect.y += 24f; } Widgets.Label(rect, "OCity_Dialog_Exchenge_No_Available_Exchange".Translate() + EditOrder.CountReady.ToString()); if (EditOrderIsMy) { rect.xMin += 250; Widgets.Label(rect, "OCity_Dialog_Exchenge_Done_Once".Translate() + EditOrder.CountFnished.ToString()); rect.xMin = 0; } rect.y += 24f; if (EditOrderIsMy) { Widgets.Label(rect, "OCity_Dialog_Exchenge_We_Give".Translate()); rect.y += 24f; EditOrderShowSellThings(ref rect); Widgets.Label(rect, "OCity_Dialog_Exchenge_We_Get".Translate()); rect.y += 24f; EditOrderShowBuyThings(ref rect); } else { Widgets.Label(rect, "OCity_Dialog_Exchenge_We_Get".Translate()); rect.y += 24f; EditOrderShowBuyThings(ref rect); Widgets.Label(rect, "OCity_Dialog_Exchenge_We_Give2".Translate(EditOrder.Owner.Login)); rect.y += 24f; EditOrderShowSellThings(ref rect); } if (EditOrder.PrivatPlayers == null || EditOrder.PrivatPlayers.Count == 0) { Widgets.Label(rect, "OCity_Dialog_Exchenge_No_User_Restrictions".Translate()); rect.y += 24f; } else { Widgets.Label(rect, "OCity_Dialog_Exchenge_User_Restrictions".Translate()); rect.y += 24f; for (int i = 0; i < EditOrder.PrivatPlayers.Count; i++) { var rect3 = new Rect(rect.x, rect.y, 24f, 24f); Widgets.Label(rect3, EditOrder.PrivatPlayers[i].Login); rect3 = new Rect(rect.xMax - 24f, rect.y, 24f, 24f); if (EditOrderIsMy && Widgets.ButtonImage(rect3, IconDelTex)) { EditOrder.PrivatPlayers.RemoveAt(i--); } rect.y += 24f; } } var rect4 = new Rect(rect); rect4.width = 150f; if (Widgets.ButtonText(rect4.ContractedBy(1f) , "OCity_Dialog_Exchenge_Add_User".Translate() , true, false, true)) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); var editOrder = EditOrder; var list = SessionClientController.Data.Players.Keys .Where(p => !editOrder.PrivatPlayers.Any(pp => pp.Login == p) && p != "system") .Select(p => new FloatMenuOption(p, () => { if (editOrder.PrivatPlayers.Any(pp => pp.Login == p)) { return; } editOrder.PrivatPlayers.Add(SessionClientController.Data.Players[p].Public); })) .ToList(); if (list.Count == 0) { return; } var menu = new FloatMenu(list); Find.WindowStack.Add(menu); return; } }
/// <summary> /// Начинаем процесс, первые запросы информации /// </summary> /// <param name="connect"></param> public void Start(SessionClient connect) { Loger.Log("Client GameAttackHost Start 1"); var tolient = connect.AttackOnlineHost(new AttackHostToSrv() { State = 2 }); if (!string.IsNullOrEmpty(connect.ErrorMessage)) { ErrorBreak(connect.ErrorMessage); return; } AttackerLogin = tolient.StartInitiatorPlayer; InitiatorPlaceServerId = tolient.InitiatorPlaceServerId; HostPlaceServerId = tolient.HostPlaceServerId; Loger.Log("Client GameAttackHost Start 2 " + tolient.HostPlaceServerId); LongEventHandler.QueueLongEvent(delegate { try { Loger.Log("Client GameAttackHost Start 3"); var hostPlace = UpdateWorldController.GetWOByServerId(HostPlaceServerId) as MapParent; var cloneMap = hostPlace.Map; var toSrvMap = new AttackHostToSrv() { State = 4, TerrainDefNameCell = new List <IntVec3S>(), TerrainDefName = new List <string>(), Thing = new List <ThingTrade>(), ThingCell = new List <IntVec3S>() }; toSrvMap.MapSize = new IntVec3S(cloneMap.Size); CellRect cellRect = CellRect.WholeMap(cloneMap); cellRect.ClipInsideMap(cloneMap); //почва Loger.Log("Client GameAttackHost Start 4"); foreach (IntVec3 current in cellRect) { var terr = cloneMap.terrainGrid.TerrainAt(current); toSrvMap.TerrainDefNameCell.Add(new IntVec3S(current)); toSrvMap.TerrainDefName.Add(terr.defName); } //скалы, преграды и строения без пешек и без растений не деревьев, вывести кол-во Loger.Log("Client GameAttackHost Start 5"); foreach (IntVec3 current in cellRect) { foreach (Thing thc in Find.CurrentMap.thingGrid.ThingsAt(current).ToList <Thing>()) { if (thc is Pawn) { continue; } //из растений оставляем только деревья if (thc.def.category == ThingCategory.Plant && !thc.def.plant.IsTree) { continue; } if (thc.Position != current) { continue; } var tt = ThingTrade.CreateTrade(thc, thc.stackCount, false); toSrvMap.ThingCell.Add(new IntVec3S(current)); toSrvMap.Thing.Add(tt); } } Loger.Log("Client GameAttackHost Start 6"); SessionClientController.Command((connect0) => { Loger.Log("Client GameAttackHost Start 7"); connect0.AttackOnlineHost(toSrvMap); if (!string.IsNullOrEmpty(connect0.ErrorMessage)) { ErrorBreak(connect0.ErrorMessage); return; } //Ждем и получаем пешки атакующего и добавляем их Loger.Log("Client GameAttackHost Start 8"); List <ThingEntry> pawnsA = null; var s1Time = DateTime.UtcNow; while (true) { var toClient5 = connect0.AttackOnlineHost(new AttackHostToSrv() { State = 5 }); if (!string.IsNullOrEmpty(connect0.ErrorMessage)) { ErrorBreak(connect0.ErrorMessage); return; } pawnsA = toClient5.Pawns; if (pawnsA != null && pawnsA.Count > 0) { break; } if ((DateTime.UtcNow - s1Time).TotalSeconds > 20) { ErrorBreak("Timeout"); return; } } if (!string.IsNullOrEmpty(connect0.ErrorMessage)) { ErrorBreak(connect0.ErrorMessage); return; } Loger.Log("Client GameAttackHost Start 9"); //Потом добавляем список к отправке SendedPawnsId = new HashSet <int>(); SendedState = new Dictionary <int, int>(); ToUpdateStateId = new List <int>(); ToUpdateState = new List <Thing>(); ToSendDeleteId = new HashSet <int>(); ToSendAddId = new HashSet <int>(); ToSendThingAdd = new HashSet <Thing>(); AttackingPawns = new List <Pawn>(); AttackingPawnDic = new Dictionary <int, int>(); AttackingPawnJobDic = new Dictionary <int, AttackPawnCommand>(); AttackUpdateTick = 0; GameMap = cloneMap; UIEventNewJobDisable = true; var cellPawns = GameUtils.SpawnCaravanPirate(cloneMap, pawnsA, (th, te) => { var p = th as Pawn; if (p == null) { return; } AttackingPawns.Add(p); AttackingPawnDic.Add(p.thingIDNumber, te.OriginalID); //задаем команду стоять и не двигаться (но стрелять если кто в радиусе) Loger.Log("Client GameAttackHost Start 9 StartJob Wait_Combat "); p.playerSettings.hostilityResponse = HostilityResponseMode.Ignore; p.jobs.StartJob(new Job(JobDefOf.Wait_Combat) { playerForced = true, expiryInterval = int.MaxValue, checkOverrideOnExpire = false, } , JobCondition.InterruptForced); /* * if (p.Label == "Douglas, Клерк") * { * //todo для теста не забыть удалить! * var pp = p; * var th = new Thread(() => * { * Thread.Sleep(5000); * while (true) * { * Thread.Sleep(1000); * try * { * var jj = pp.jobs.curJob; * Loger.Log("Host ThreadTestJob " + pp.Label + " job=" + (jj == null ? "null" : jj.def.defName.ToString())); * } * catch * { } * } * }); * th.IsBackground = true; * th.Start(); * } */ }); UIEventNewJobDisable = false; Loger.Log("Client GameAttackHost Start 10"); CameraJumper.TryJump(cellPawns, cloneMap); TimerObj = SessionClientController.Timers.Add(200, AttackUpdate); //включаем обработку событий урона и уничтожения объектов GameAttackTrigger_Patch.ActiveAttackHost.Add(GameMap, this); Loger.Log("Client GameAttackHost Start 11"); }); } catch (Exception ext) { Loger.Log("GameAttackHost Start() Exception " + ext.ToString()); } }, "...", false, null); }