public static Quest Action(string id) { FDataAction da = L.b.actions[id]; Quest q = new Quest(da.id, da.Name(), da.Icon).AddAction(id, ""); return(q); }
private void PerformAction(ActionHolders holder, ActionHolder action, MapElementInfo info) { FDataAction da = action.DataAction(); //can use? if (!action.req.Check(info.Player(), info, info.Pos())) { //TODO not hardcoded //start interact action? if (da.mapElement && holder.Contains("interact") && da.field == "near") { PerformAction(holder, holder.Get("interact"), info); return; } ShowPanelMessageError(action.req.Desc(info.Player(), info, info.Pos())); return; } //check ap if (action.cost > info.data.ap) { ActionHelper.WaitRound(holder, action, info, info.Pos()); return; } string mess = holder.Perform(action, ActionEvent.Direct, S.ActPlayer(), info, info.Pos()); if (mess != null) { ShowPanelMessageError(mess); } }
protected override void ClickSecond() { //load options WindowBuilderSplit b = WindowBuilderSplit.Create("Interaction","Perform"); foreach(var action in mapElementInfo.data.action.actions) { FDataAction data = action.DataAction(); if (!data.mapElement || data.field != "near") continue; //found it? if (!action.req.Check(S.ActPlayer(), mapElementInfo, LastClickPos, true)) { continue; } ActionInteractSplitElement be = new ActionInteractSplitElement(mapElementInfo.data.action, action, mapElementInfo, LastClickPos); be.disabled = action.req.Desc(S.ActPlayer(), mapElementInfo, LastClickPos); be.audioPerform = data.sound; b.Add(be); } //is empty? if (b.Count() == 0) { mapElementInfo.UI().ShowPanelMessageError("No interaction with neighbors found."); b.CloseWindow(); return; } b.Finish(); }
public static void WaitRound(ActionHolders holder, ActionHolder action, MapElementInfo info, NVector pos, int cost = -1, string sett = null, ActionEvent evt = ActionEvent.Direct) { FDataAction da = action.DataAction(); cost = cost == -1 ? action.cost : cost; int round = (int)Math.Ceiling((1f * cost - info.data.ap) / info.data.apMax); WindowPanelBuilder wpb = WindowPanelBuilder.Create($"Wait for {da.Name()}?"); wpb.panel.RichText(da.Desc()); wpb.panel.AddImageLabel($"Action {da.Name()} need {cost - info.data.ap} AP more. You can wait {round} rounds.", "round"); wpb.panel.AddButton($"Wait {round} rounds", () => { var aw = new ActionWaiting(action, holder, pos); aw.apMax = cost; aw.sett = sett; aw.evt = evt; info.SetWaitingAction(aw); L.b.animations.Create("sandClock", pos); OnMapUI.Get().UpdatePanel(info.Pos()); wpb.Close(); }); wpb.AddClose(); wpb.Finish(); }
public virtual void BuildPanel(ActionDisplaySettings sett) { FDataAction da = L.b.actions[id]; string h = sett.header ?? (S.Debug() ? $"{da.Name()} ({id})" : da.Name()); if (sett.compact) { sett.panel.AddImageLabel(h, da.Icon); return; } sett.panel.AddHeaderLabel(h); if (S.Debug()) { sett.panel.AddSubLabel("triggerWait",sett.holder.triggerWait.ToString()); } if (sett.holder.triggerCount > 0) { string s = sett.holder.triggerWait ? " in" : " "; if (sett.holder.trigger == ActionEvent.NextRound) { sett.panel.AddImageLabel($"Action will be performed{s} {sett.holder.triggerCount} rounds.", "build"); } else if (sett.holder.trigger == ActionEvent.Direct) { sett.panel.AddLabel($"You can perform this action{s} {sett.holder.triggerCount} times."); } } else { switch (sett.holder.trigger) { case ActionEvent.Direct: sett.panel.AddImageLabel($"You can performed it directly for {sett.holder.cost} AP","ap"); break; case ActionEvent.FinishConstruct: sett.panel.AddLabel("It will be performed after finish construction."); break; case ActionEvent.NextRound: sett.panel.AddLabel("It will be performed every round."); break; default: sett.panel.AddLabel($"It will be performed {sett.holder.trigger}"); break; } } //add req? if (sett.addReq) { if (sett.pos == null) sett.holder.req.BuildPanel(sett.panel); else sett.holder.req.BuildPanel(sett.panel, sett.mapElement, sett.pos); } }
/// <summary> /// Show the action with the key, if possible /// </summary> /// <param name="action"></param> /// <returns></returns> public string ActionName(FDataAction action) { //has the action an input? if (!ContainsKey(action.id)) { return(action.Name()); } return(this[action.id].Name()); }
public void StartPlayerRound() { //has a waiting round? if (data.waiting == null) { return; } ActionHolder a = data.action.actions[data.waiting.actionPos]; FDataAction da = a.DataAction(); //perform every turn? if (data.waiting.endless) { if (da.interaction) { AddNoti(S.T("actionInteraction", data.name, da.Name()), da.Icon); data.waiting.needPerform = true; } else { string erg2 = data.action.Perform(a, ActionEvent.NextRound, Player(), this, data.waiting.pos); AddNoti(S.T("actionPerform", data.name, da.Name(), erg2), da.Icon); } return; } //wait more? if (data.waiting.apMax > data.ap + data.waiting.ap) { data.waiting.ap += data.ap; data.ap = 0; return; } Debug.Log(da.Name() + da.interaction); if (da.interaction) { AddNoti(S.T("actionInteraction", data.name, da.Name()), da.Icon); data.waiting.needPerform = true; } else { PerformWaitingAction(); } }
public string Status(int playerId) { string text = " "; if (!Owner(playerId)) { return($"{gameObject.name} belongs to {Player().name}"); } if (IsUnderConstruction()) { return($"{gameObject.name} under construction ({(int) (GetComponent<Construction>().GetConstructionProcent()*100)}%) {data.info.LastInfo()}"); } if (data.waiting != null) { ActionHolder a = data.action.actions[data.waiting.actionPos]; FDataAction da = a.DataAction(); text += $"Prepare {da.Name()}"; if (data.waiting.endless) { text += $" (repeat unlimited)."; } else { text += $" ({TextHelper.Proc(data.waiting.ap, data.waiting.apMax)})."; } if (S.Debug()) { text += data.ap + "/" + data.waiting.ap + "/" + data.waiting.apMax; } } //add hp? string hp = data.hp < data.hpMax ? $"HP:{data.hp}/{data.hpMax}, " : ""; return($"{gameObject.name} {hp}AP:{data.ap}/{data.apMax}{text} {data.info.LastInfo()}"); }
public void PerformWaitingAction() { //has a waiting round? if (data.waiting == null) { return; } ActionHolder a = data.action.actions[data.waiting.actionPos]; FDataAction da = a.DataAction(); data.ap = data.waiting.apMax - data.waiting.ap; data.ap += data.waiting.ap; a.data["waiting"] = data.waiting.sett; string erg = data.action.Perform(a, data.waiting.evt, Player(), this, data.waiting.pos); a.data.Remove("waiting"); data.ap = data.waiting.apMax - data.waiting.ap; AddNoti(S.T("actionPerform", data.name, da.Name(), erg), da.Icon); data.waiting = null; }
protected void AddButtons() { //remove actions UIHelper.ClearChild(actions); //has active action? if (ActiveAction != null) { ShowPanelMessage(ActiveAction.PanelMessage()); FDataAction action = ActiveAction.DataAction(); UIHelper.CreateImageTextButton(S.T("actionCancel", action.Name()), action.Sprite(), actions.transform, () => { OnMapUI.Get().SetActiveAction(null, active.GetComponent <BuildingInfo>() != null); }, "cancel"); return; } //has waiting action? if (active.data.waiting != null) { //can perform? if (active.data.waiting.needPerform) { active.PerformWaitingAction(); return; } ActionHolder a = active.data.action.actions[active.data.waiting.actionPos]; UIHelper.CreateImageTextButton(S.T("actionWaitingCancel"), a.DataAction().Sprite(), actions.transform, () => { active.data.ap = Math.Max(0, Math.Min(active.data.waiting.ap, active.data.apMax)); active.SetWaitingAction(null); OnMapUI.Get().UpdatePanel(active.Pos()); }, "cancel"); return; } AddAllActionButtons(); }
public void AddNewActionButton(ActionHolders holder, ActionHolder action, MapElementInfo info, GameObject actionPanel) { if (action == null) { throw new MissingMemberException($"Action for {info} is missing."); } //BasePerformAction ba = action.PerformAction(); FDataAction da = action.DataAction(); //can add under construction? if (info.IsUnderConstruction() && !da.useUnderConstruction) { return; } //can add from diff player? if (da.onlyOwner && !info.Owner(S.ActPlayerID())) { return; } //can add final? if (!action.req.Check(S.ActPlayer(), info, info.Pos(), true)) { return; } Button button = UIElements.CreateImageButton(da.Sprite(), actionPanel.transform, () => { PerformAction(holder, action, info); }, da.sound); UIHelper.HoverEnter(button, () => { ShowPanelMessage(S.T("actionTooltip", LSys.tem.inputs.ActionName(da), action.cost, info.data.ap)); }, () => { ShowPanelMessage(info.Status(S.ActPlayerID())); }); }
public override void PreRun() { //calc size int diff = 1; //string moveTyp = ((UnitInfo) mapElementInfo).dataUnit.movement; //collect move for (int x = Math.Max(0,initPos.x-diff); x <= Math.Min(GameMgmt.Get().data.map.width-1,initPos.x+diff); x++) { for (int y = Math.Max(0,initPos.y-diff); y <= Math.Min(GameMgmt.Get().data.map.height-1,initPos.y+diff); y++) { //check enemy and fog //TODO combine with unit check NVector dPos = new NVector(x, y, initPos.level); if (!player.fog.Visible(dPos)) { continue; } //terrain ok? //TODO not hardcoded if (GameMgmt.Get().newMap.Terrain(dPos).category == "unknown") continue; //action possible? foreach (var action in mapElementInfo.data.action.actions) { FDataAction data = action.DataAction(); if (!data.mapElement || data.field != "near") continue; if (!action.req.Check(S.ActPlayer(), mapElementInfo, dPos, true)) { continue; } //Debug.Log($"{data.name}: {dPos}"); // if (Points.Count(p => p.x == x && p.y == y) > 0) // { // Points.RemoveAll(Points.Where(p => p.x == x && p.y == y)); // } if (!S.Unit().Free(dPos)) { //TODO color own? if (S.Unit().At(dPos).Owner(S.ActPlayerID())) { Color(dPos,2); } else { Color(dPos,1); } } else { Color(dPos,3); } break; } } } //nothing found? if (Points.Count == 0) { mapElementInfo.UI().ShowPanelMessageError("No interaction found."); OnMapUI.Get().SetActiveAction(null,mapElementInfo.IsBuilding()); NAudio.PlayCancel(); } }