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()); } }
public virtual void Click(NVector pos) { //known click? if (pos.Equals(LastClickPos)) { ClickSecond(); OnMapUI.Get().SetActiveAction(null, false); return; } //new Click? LastClickPos = pos; if (Points.Count(p => p.x == LastClickPos.x && p.y == LastClickPos.y) == 0) { NAudio.PlayCancel(); ClickFirstCancel(); } else { ClickFirst(); } }
public override void Click(NVector pos) { //known click? if (pos.Equals(LastClickPos)) { ClickSecond(); OnMapUI.Get().SetActiveAction(null, false); return; } //new Click? LastClickPos = pos; if (S.Unit().At(pos) != null) { NAudio.PlayCancel(); ClickFirstCancel(); } else { ClickFirst(); } }
private void MoveToPos(Player player, UnitInfo unit, ActionHolder holder) { DataUnit dUnit = unit.dataUnit; NVector dPos = new NVector(holder.data["pos"]); int level = unit.Pos().level; //go to this field List <PPoint> points = S.Map().PathFinding(level).Path(player, dUnit.movement, unit.Pos(), dPos); NVector last = null; Debug.Log("Go to Goal " + unit.Pos() + " " + dPos); //find last possible point foreach (PPoint pp in points) { NVector p = new NVector(pp.x, pp.y, level); //free field? string s = unit.Passable(p); Debug.Log(p + ": " + s); if (s != null) { break; } //save it last = p; } Debug.Log("Go to Goal " + last); //move their? if (last == null) { if (holder.data.ContainsKey("posTried")) { unit.SetLastInfo(S.T("actionRepeatErrorMove", holder.DataAction().Name())); unit.SetRepeatAction(null); } else { unit.SetLastInfo(S.T("actionRepeatErrorPath", holder.DataAction().Name())); if (unit.data.ap == unit.data.apMax) { holder.data["posTried"] = "yes"; } } return; } //move their unit.MoveTo(last, true); holder.data.Remove("posTried"); if (dPos.Equals(last)) { //perform it holder.data.Remove("pos"); PerformRepeat(player, unit, dPos, holder); } //has enough ap for a next exploration? //todo dynamic if (dUnit.ap >= 10) { //Explore(player, unit, pos, holder); } }