Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos,
                                        ActionHolder holder)
        {
            string[] keys;
            if (holder.data.ContainsKey("upgrade"))
            {
                keys = SplitHelper.Separator(holder.data["upgrade"]);
            }
            else
            {
                keys = info.IsBuilding()?L.b.buildings.Keys().ToArray():L.b.units.Keys().ToArray();
            }

            //load buildings
            WindowBuilderSplit b = WindowBuilderSplit.Create(holder.DataAction().Desc(), holder.DataAction().Name());

            {
                foreach (string key in keys)
                {
                    BaseDataBuildingUnit build = info.IsBuilding()?(BaseDataBuildingUnit)L.b.buildings[key]:L.b.units[key];
                    if (build.req.Check(player, info, pos, true))
                    {
                        BuildUpgradeSplitElement be = new BuildUpgradeSplitElement(build, info, pos, b);
                        be.disabled = build.req.Desc(player, info, pos);
                        b.Add(be);
                        //win.AddBuilding(build.id);
                    }
                }
            }

            b.Finish();
        }
Esempio n. 3
0
        public override bool Check(Player player, MapElementInfo onMap, string sett, NVector pos)
        {
            if (onMap == null || !onMap.IsBuilding())
            {
                onMap = S.Building(pos);
            }

            return(onMap != null && onMap.baseData.category.Contains(sett));
        }
Esempio n. 4
0
        public override string Desc(Player player, MapElementInfo onMap, string sett, NVector pos)
        {
            if (onMap == null || !onMap.IsBuilding())
            {
                onMap = S.Building(pos);
            }

            return(Desc(player, sett) + (onMap == null?S.T("reqBuildingCategoryNone"):S.T("reqBuildingCategoryHere", onMap.baseData.category)));
        }
Esempio n. 5
0
        protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos,
                                        ActionHolder holder)
        {
            if (!info.IsBuilding())
            {
                MoveUnit(info, pos);
                return;
            }

            MoveBuilding(info, pos, holder);
        }
Esempio n. 6
0
        protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos, ActionHolder holder)
        {
            //get tilemap
            tileMap = GameMgmt.Get().newMap[pos.level].border.GetComponent <Tilemap>();
            Points  = new List <PPoint>();

            //save caller
            this.player    = player;
            mapElementInfo = info;
            this.initPos   = pos;
            action         = holder;

            //set as active action
            OnMapUI.Get().SetActiveAction(this, mapElementInfo.IsBuilding());
            PreRun();
        }
Esempio n. 7
0
        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());
            }
        }
Esempio n. 8
0
        protected void BuildPanelIntern(ActionDisplaySettings sett, MapElementInfo info)
        {
            sett.header = TextHelper.Cap(S.T("attack", info.name));
            base.BuildPanel(sett);

            if (sett.compact)
            {
                return;
            }

            sett.panel.AddHeaderLabel(S.T("attackSelf", sett.mapElement.name));
            sett.panel.AddSubLabelT("atk", sett.mapElement.data.atk, "atk");
            sett.panel.AddSubLabelT("dam", S.T("attackDam", sett.mapElement.baseData.damMin, sett.mapElement.baseData.damMax),
                                    "damage");

            sett.panel.AddHeaderLabel(S.T("attackNonSelf", info.name));
            sett.panel.AddSubLabelT("def", info.data.def, "def");

            //both units?
            if (!sett.mapElement.IsBuilding() && !info.IsBuilding())
            {
                bool found = false;
                foreach (var fm in L.b.fightModis.Values())
                {
                    if (!fm.req.Check(sett.mapElement, sett.pos))
                    {
                        continue;
                    }

                    if (!found)
                    {
                        sett.panel.AddHeaderLabelT("fightmodi");
                        found = true;
                    }

                    sett.panel.AddImageLabel(fm.Desc(), fm.Icon);
                }
            }
        }
Esempio n. 9
0
 protected override bool CheckMapElement(MapElementInfo mapElement, string sett)
 {
     return(!mapElement.IsBuilding() && ((UnitInfo)mapElement).dataUnit.type == sett);
 }
Esempio n. 10
0
 public override void ShowLexicon(PanelBuilder panel, MapElementInfo onMap, NVector pos)
 {
     base.ShowLexicon(panel, onMap != null && onMap.IsBuilding()?null:onMap, pos);
 }
Esempio n. 11
0
        public void Perform(Player player, MapElementInfo mapElementInfo, NVector pos, bool ani)
        {
            //mapElementInfo.data.ap -= cost;
            var    target = S.MapElement(pos);
            string msg    = null;
            int    ap     = 0;
            int    chance = mapElementInfo.data.spells.CalcChance(id);

            mapElementInfo.data.spells.Cast(id);
            target = (target != null) ? target : mapElementInfo;
            //can perform?
            if (chance > Random.Range(0, 100))
            {
                //calc cost
                foreach (var ah in action.actions)
                {
                    ap += ah.DataAction().cost;
                }

                mapElementInfo.data.ap += ap; //tmp for spell using
                msg = action.Performs(ActionEvent.All, player, target, pos);

                //success?
                if (String.IsNullOrEmpty(msg))
                {
                    if (ani && !String.IsNullOrEmpty(animation))
                    {
                        L.b.animations.Create(animation, pos);
                        NAudio.Play(Sound);
                        if (!mapElementInfo.IsBuilding())
                        {
                            ((UnitInfo)mapElementInfo).UnitAnimator().PlayIdleAnimation(UnitAnimatorType.Cast);
                        }
                    }

                    mapElementInfo.AddNoti(S.T("spellSuccess", Name()), Icon);

                    return;
                }
            }

            //falure

            //calc cost
            ap = 0;
            foreach (var ah in action.actions)
            {
                ap += ah.DataAction().cost;
            }

            mapElementInfo.data.ap += ap; //tmp for spell using
            var nmsg = actionFail.Performs(ActionEvent.All, player, target, pos);

            if (ani)
            {
                L.b.animations.Create("broken", pos);
                mapElementInfo.UI().ShowPanelMessageError(S.T("spellError", Name()));
            }

            msg = $"{msg} {nmsg}";

            mapElementInfo.AddNoti(S.T("spellError", Name(), msg), Icon);
        }