private void ShowUnitAttack(MapElementInfo own, MapElementInfo enemy) { int x = own.Pos().x - enemy.Pos().x; int y = own.Pos().y - enemy.Pos().y; Debug.LogWarning(own.name + " " + own.IsBuilding()); //show attacker animation if (!own.IsBuilding()) { UnitInfo unit = (UnitInfo)own; var sq = DOTween.Sequence(); sq.Append(unit.transform.DOMove(new Vector3(unit.Pos().x + 0.5f - x / 4f, unit.Pos().y - y / 4f), 1)); sq.Append(unit.transform.DOMove(new Vector3(unit.Pos().x + 0.5f, unit.Pos().y), 1)); unit.UnitAnimator().PlayFightAnimation(x > 0?UnitAnimatorType.AttackEast:x < 0?UnitAnimatorType.AttackWest:y < 0?UnitAnimatorType.AttackSouth:UnitAnimatorType.AttackNorth); } //show defender animation if (!enemy.IsBuilding()) { UnitInfo unit = (UnitInfo)enemy; var sq = DOTween.Sequence(); sq.Append(unit.transform.DOMove(new Vector3(unit.Pos().x + 0.5f - x / 4f, unit.Pos().y - y / 4f), 1)); sq.Append(unit.transform.DOMove(new Vector3(unit.Pos().x + 0.5f, unit.Pos().y), 1)); unit.UnitAnimator().PlayFightAnimation(x > 0?UnitAnimatorType.DefendEast:x < 0?UnitAnimatorType.DefendWest:y < 0?UnitAnimatorType.DefendSouth:UnitAnimatorType.DefendNorth); } }
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); } }
public override void ShowLexicon(PanelBuilder panel, MapElementInfo info, NVector pos) { base.ShowLexicon(panel); panel.AddImageLabel(S.T("spellCostUnit", cost, info.data.ap), "ap"); panel.AddLabel(S.T("spellChance", info.data.spells.CalcChance(id))); req.BuildPanel(panel, info, info.Pos()); reqTarget.BuildPanel(panel); var ah = new ActionDisplaySettings(panel, S.ActPlayer(), info, info.Pos(), null); action.BuildPanelT(ah, "spellPerformSuccess"); actionFail.BuildPanelT(ah, "spellPerformFail"); }
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(); }
/// <summary> /// Calc the damage /// </summary> /// <param name="self"></param> /// <param name="nonSelf"></param> /// <returns></returns> private int CalcDamage(MapElementInfo self, MapElementInfo nonSelf) { float dam = Random.Range(self.baseData.damMin, self.baseData.damMax + 1); int atk = self.baseData.atk, def = nonSelf.baseData.def; foreach (var fm in L.b.fightModis.Values()) { if (!fm.req.Check(self, nonSelf.Pos())) { continue; } dam *= (1 + fm.modi / 100f); } // check multi if (atk >= def) { dam *= 1 + 0.05f * (atk - def); } else { dam *= 1 - 0.025f * (def - atk); } return((int)dam); }
protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos, ActionHolder holder) { //info.data.ap = 0; if (evt == ActionEvent.Direct) { //is the townhall or unit? if (info.IsBuilding()) { //transform to the other unit? var unit = S.Unit(info.Pos()); var cost = ConvertHelper.Int(holder.data["cost"]); if (unit.data.ap < cost) { //clone action var ua = Create(holder.data["cost"]); CreateAddCount(ua, ActionEvent.Direct, "1", false); ua.cost = cost; ua.data["pos"] = unit.Pos().ToString(); unit.data.action.Add(ua); ActionHelper.WaitRound(unit.data.action, ua, unit, unit.Pos()); return; } info.SetRepeatAction(new ActionWaiting(holder, info.data.action, pos)); OnMapUI.Get().UpdatePanel(info.Pos()); return; } //moved? var opos = new NVector(holder.data["pos"]); if (!opos.Equals(info.Pos())) { OnMapUI.Get().unitUI.ShowPanelMessageError(S.T("occupyMoved")); return; } //transfer var build = S.Building(info.Pos()); build.Town().Transfer(info.data.playerId); OnMapUI.Get().UpdatePanel(info.Pos()); } }
protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos, ActionHolder holder) { //info.data.ap = 0; if (evt == ActionEvent.Direct) { info.SetRepeatAction(new ActionWaiting(holder, info.data.action, pos)); OnMapUI.Get().UpdatePanel(info.Pos()); } }
public override void ShowDetail(PanelBuilder panel) { panel.AddSubLabel("Position", _mapElementInfo.Pos().ToString()); panel.AddHeaderLabel("HP"); panel.AddInput("HP", _mapElementInfo.data.hp, (s => { _mapElementInfo.data.hp = s; })); panel.AddHeaderLabel("AP"); panel.AddInput("AP", _mapElementInfo.data.ap, (s => { _mapElementInfo.data.ap = s; })); panel.AddButton("Set Finish", _mapElementInfo.FinishConstruct); //display all actions foreach (var act in _mapElementInfo.data.action.actions) { act.PerformAction().BuildPanel(new ActionDisplaySettings(panel, _mapElementInfo.Player(), _mapElementInfo, _mapElementInfo.Pos(), act)); } //display modis }
public virtual void Perform(MapElementInfo self, MapElementInfo nonSelf) { // calc damage int damage = CalcDamage(self, nonSelf); string a = $"{self.name} ({self.Player().name})"; string d = $"{nonSelf.name} ({nonSelf.Player().name})"; Debug.LogError("Damage:" + damage); // check it if (damage == 0) { OnMapUI.Get().unitUI.ShowPanelMessage(S.T("attackDamEqual", self.name, d)); NAudio.Play("defend"); //inform another player nonSelf.AddNoti($"Defended against {a}", self.baseData.Icon); return; } // counter fight if (damage < 0) { Perform(nonSelf, self); OnMapUI.Get().unitUI.ShowPanelMessage($"{d} fight back."); return; } // win ShowUnitAttack(self, nonSelf); nonSelf.AddHp(-damage); L.b.animations.Hp(-damage, nonSelf.Pos(), nonSelf); OnMapUI.Get().unitUI.ShowPanelMessage($"You won. {d} lose {damage} HP."); nonSelf.AddNoti($"{a} attacked you. {nonSelf.name} lose {damage} HP.", self.baseData.Icon); //int oX = defensor.getX(); //int oY = defensor.getY(); //UiHelper.textAnimation("-" + damage + " hp", oX, oY, true, Color.SALMON); //TODO add animation //defensor.getActor().addAction(Actions.sequence(Actions.color(Color.RED, 1), Actions.color(Color.WHITE, 1))); //getActor().addAction(Actions.parallel(Actions.sequence(Actions.moveTo(oX * 32, oY * 32, 1), Actions.moveTo(x * 32, y * 32, 1)), // Actions.sequence(Actions.color(Color.BLACK, 1), Actions.color(Color.WHITE, 1)))); }
protected bool ProduceOneRes(ActionEvent evt, MapElementInfo info, NVector pos, int val, string res) { //Debug.Log(res+" "+val+" "+GameMgmt.Get().data.map.ResGenContains(pos, res)); //remove? if (val > 0 && GameMgmt.Get().data.map.ResGenContains(pos, res)) { int rval = GameMgmt.Get().data.map.ResGen(pos, res); if (rval < 200 && Random.Range(0, 200) > rval) { val = 1; } if (rval <= 0) { info.SetLastInfo(S.T("produceDepositEmpty", res)); return(false); } if (rval < 20) { info.SetLastInfo(S.T("produceDepositNearlyEmpty", res)); } GameMgmt.Get().data.map.ResGenAdd(pos, res, -val); } ResType r = evt == ActionEvent.NextRound ? ResType.Produce : evt == ActionEvent.FinishConstruct ? ResType.Construction : ResType.Gift; double v = val; //add modi? if (r == ResType.Produce && val > 0) { v = L.b.modifiers[C.ProduceModi].CalcModi(v, info.Player(), info.Pos()); } //todo right comb? info.Town().AddRes(res, v, r); return(true); }
public override void ShowDetail(PanelBuilder panel) { _craft.ShowLexicon(panel); _craft.req.BuildPanel(panel, _info, _info.Pos()); panel.AddHeaderLabel("Actions"); panel.AddImageTextButton(_craft.Name(), _craft.Icon, () => _holder.data["craft" + NextFreeID()] = $"{_craft.id}:1" ); panel.AddImageTextButton($"10x {_craft.Name()}", _craft.Icon, () => _holder.data["craft" + NextFreeID()] = $"{_craft.id}:10" ); panel.AddImageTextButton($"100x {_craft.Name()}", _craft.Icon, () => _holder.data["craft" + NextFreeID()] = $"{_craft.id}:100" ); panel.AddImageTextButton($"endless {_craft.Name()}", _craft.Icon, () => _holder.data["craft" + NextFreeID()] = $"{_craft.id}:-1" ); }
protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos, ActionHolder holder) { //dying? if (holder.trigger == ActionEvent.NextRound) { info.Kill(); info.AddNoti(S.T("destroyDie", info.name), DataAction().Icon); return; } WindowPanelBuilder wpb = WindowPanelBuilder.Create(S.T("destroyKill", info.name)); wpb.panel.AddImageTextButton(S.T("destroyKill", info.name), info.Sprite(), (() => { info.Kill(); OnMapUI.Get().UpdatePanel(info.Pos()); wpb.Close(); })); wpb.AddClose(); wpb.Finish(); }
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 ShowLexicon(PanelBuilder panel, MapElementInfo onMap, NVector pos) { if (onMap == null) { ShowIntern(panel, null, pos); ActionDisplaySettings sett = new ActionDisplaySettings(panel, S.ActPlayer(), null, pos, null); sett.compact = true; action.BuildPanelT(sett); return; } if (!onMap.Owner(S.ActPlayerID())) { ShowLexicon(panel); return; } pos = onMap.Pos(); ShowIntern(panel, onMap, pos); onMap.data.action.BuildPanelT(new ActionDisplaySettings(panel, onMap.Player(), onMap, pos, null)); }
public void ShowOwn(PanelBuilder panel, MapElementInfo info) { base.ShowLexicon(panel); req.BuildPanel(panel, info, info.Pos()); action.BuildPanelT(new ActionDisplaySettings(panel, S.ActPlayer(), info, info.Pos(), null)); }
public ItemSelectSplitInfo(MapElementInfo info, Button button, string id, Item item) : base(info, button, id, item.Name(), item.Sprite()) { this.item = item; disabled = item.req.Desc(info, info.Pos()); }
// Update is called once per frame void Update() { //find key? if (findKey != null) { if (Input.anyKey) { foreach (var key in keyValues) { if (key.ToString().StartsWith("mouse")) { continue; } if (Input.GetKeyDown((KeyCode)key)) { findKey((KeyCode)key); } } } return; } if (LSys.tem == null || LSys.tem.inputs == null) { Debug.Log($"LSys.tem is not loaded, can not perform key check. LSys.tem:${LSys.tem != null} LSys.tem.inputs:${LSys.tem != null && LSys.tem.inputs != null}"); return; } //check all buttons foreach (InputKey key in LSys.tem.inputs.Values()) { //active? if (key.Hidden) { continue; } //pressed? if (!Input.GetKeyDown(key.KeyCode())) { continue; } //req fullfilled? if (!key.req.Check(ActPlayer(), active, active?.Pos())) { if (S.IsGame()) { OnMapUI.Get().ShowPanelMessageError(key.req.Desc(ActPlayer(), active, active?.Pos())); } else { //TODO show error NAudio.PlayBuzzer(); } continue; } try { if (key.IsGameButton()) { PressGameButton(key); return; } if (key.IsAction()) { PressAction(key); return; } PressHidden(key); return; } catch (Exception e) { ExceptionHelper.ShowException(e); } } MouseMoveMap(); }
public override void ShowDetail(PanelBuilder panel) { foreach (var action in info.data.action.actions) { action.PerformAction().BuildPanel(new ActionDisplaySettings(panel, info.Player(), info, info.Pos(), action)); } }
private static void Cast(Spell spell, MapElementInfo go) { //find destination ActionHolder ah = new ActionHolder(); ah.data["waiting"] = spell.id; LClass.s.GetNewAction("magicSelect").PerformCheck(ActionEvent.Direct, S.ActPlayer(), go, go.Pos(), ah); }
protected void RemoveOld() { //remove old? if (_info.data.items.ContainsKey(id)) { _info.Town().AddRes(_info.data.items[id], 1, ResType.Equip); L.b.items[_info.data.items[id]].action.Removes(ActionEvent.Quest, S.ActPlayer(), _info, _info.Pos()); } }
protected void SetRepeat(MapElementInfo info, NVector pos, ActionHolder holder) { info.SetRepeatAction(new ActionWaiting(holder, info.data.action, pos)); OnMapUI.Get().UpdatePanel(info.Pos()); }