Beispiel #1
0
    /// <summary>
    /// 移动建筑物到指定位置
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    public void DraggingBuildingTo(int x, int y)
    {
        //REMARK 一个建筑格子占2个小格子
        if (x % 2 == 1)
        {
            x -= 1;
        }
        if (y % 2 == 1)
        {
            y -= 1;
        }
        if (currentBuilding.GetTilePos().x == x && currentBuilding.GetTilePos().y == y)
        {
            return;
        }
        if (!draged)
        {
            draged = true;
            EventDispather.DispatherEvent(GameEvents.BEGIN_DRAG_BUILDING);
        }
        currentBuilding.SetTilePosition(new TilePoint(x, y));
        currentBuilding.view.transform.position = currentBuilding.GetRenderPosition();
        var pos = IsoHelper.GridToPosition(x, y);

        buildableView.gameObject.SetActive(true);
        buildableView.transform.position = pos;
        IsoHelper.MoveAlongCamera(buildableView.transform, 5f);
        buildArrow.transform.position = pos;
//        IsoHelper.MoveAlongCamera(buildArrow.transform,-1f);
        buildConfirm.transform.position = pos;
        IsoHelper.MoveAlongCamera(buildConfirm.transform, -1f);

        //  是否可以建造
        buildableView.SetBuildable(IsoMap.Instance.CanPlaceBuilding(x, y, currentBuilding.width, currentBuilding.height));
    }
Beispiel #2
0
    protected override void OnRelease()
    {
        if (draged)
        {
            draged = false;
            EventDispather.DispatherEvent(GameEvents.END_DRAG_BUILDING);

            //隐藏可建造绿地皮
            if (!isNewBuild && currentBuilding != null)
            {
                var buildable = IsoMap.Instance.CanPlaceBuilding(currentBuilding.GetTilePos().x,
                                                                 currentBuilding.GetTilePos().y, currentBuilding.width, currentBuilding.height);
                if (buildable)
                {
                    buildableView.gameObject.SetActive(false);

                    if (currentBuilding.GetTilePos() != new TilePoint(oldX, oldY))
                    {
                        currentBuilding.buildingVO.x = currentBuilding.GetTilePos().x;
                        currentBuilding.buildingVO.y = currentBuilding.GetTilePos().y;
                        GameManager.Instance.RequestMoveBuilding(currentBuilding);
                        oldX = currentBuilding.GetTilePos().x;
                        oldY = currentBuilding.GetTilePos().y;

                        IsoMap.Instance.InitGuardAreaMap();
                        IsoMap.Instance.ShowGuardAreaMap(true);
                    }
                }
            }
        }
    }
 public override ReqWrapper Execute()
 {
     if (type == TrapRefillReq.RefillType.All)
     {
         foreach (var buildingVo in DataCenter.Instance.Defender.buildings)
         {
             if (buildingVo.trapBuildingVO != null && buildingVo.trapBuildingVO.broken)
             {
                 var model = DataCenter.Instance.FindEntityModelById(buildingVo.cid);
                 DataCenter.Instance.RemoveResource(ResourceType.Gold, model.refillCostResourceCount);
                 buildingVo.trapBuildingVO.broken = false;
             }
         }
     }
     else if (type == TrapRefillReq.RefillType.Single)
     {
         var model = DataCenter.Instance.FindEntityModelById(building.cid);
         DataCenter.Instance.RemoveResource(ResourceType.Gold, model.refillCostResourceCount);
         building.trapBuildingVO.broken = false;
     }
     EventDispather.DispatherEvent(GameEvents.TRAP_REFILL, building);
     return(new ReqWrapper()
     {
         requestType = ReqWrapper.RequestType.TrapRefill,
         trapRefillReq = new TrapRefillReq()
         {
             refillType = type,
             sid = building == null ? 0 : building.sid,
         }
     });
 }
Beispiel #4
0
    /// <summary>
    /// 偷资源
    /// </summary>
    /// <param name="resource"></param>
    public void StolenResource(ResourceVO resource)
    {
        UnityEngine.Debug.Log("偷取:" + resource.resourceType + " " + resource.resourceCount);
        var found = false;

        foreach (var stolenResource in stolenResources)
        {
            if (stolenResource.resourceType == resource.resourceType)
            {
                stolenResource.resourceCount += resource.resourceCount;
                found = true;
                break;
            }
        }
        if (!found)
        {
            stolenResources.Add(resource);
        }
        //剩余被偷的资源量
        AddStealableResource(new ResourceVO()
        {
            resourceType = resource.resourceType, resourceCount = -resource.resourceCount
        });
        DataCenter.Instance.AddResource(resource, OwnerType.Attacker);
        EventDispather.DispatherEvent(GameEvents.STOLEN_RESOURCE, resource);
    }
Beispiel #5
0
 public override void Init()
 {
     base.Init();
     if (Entity.buildingVO.trapBuildingVO == null)
     {
         Entity.buildingVO.trapBuildingVO = new TrapBuildingVO()
         {
             broken = false
         };
     }
     if (Entity.buildingVO.trapBuildingVO.broken)
     {
         enabled = false;
         Entity.view.SwitchBody(2);//broken view
     }
     else
     {
         enabled = true;
         Entity.view.SwitchBody(1);
     }
     if (GameWorld.Instance.worldType == WorldType.Home || GameWorld.Instance.worldType == WorldType.Visit)
     {
         enabled = false;
         EventDispather.AddEventListener(GameEvents.TRAP_REFILL, OnTrapRefill);
     }
     else
     {
         Entity.HideEntity(); //  陷阱初始不可见
     }
 }
Beispiel #6
0
    /// <summary>
    /// 显示回放的UI
    /// </summary>
    public void ShowReplayUI()
    {
        UIMananger.Instance.CloseWinByType(UICloseOrHideType.CLOSE_WORLD_TYPE_REPLAY);
        UIPanel  panel;
        UISprite sprite;
        //回放防御者信息
        GameObject defenderPanel = UIMananger.Instance.ShowWin("PLG_FightReplay", "UIFightReplayDefenderPanel");

        sprite = defenderPanel.GetComponent <UISprite>();
        PanelUtil.SetPanelAnchors(sprite, UIMananger.Instance.uiLayer.transform, new Vector4(0, 0, 1, 1), new Vector4(0, sprite.width, -sprite.height, 0));
        defenderPanel.GetComponent <UIFightReplayDefenderWnd>().UpdateDefenderInfo(null, null);
        //回放攻击者信息
        GameObject attackerPanel = UIMananger.Instance.ShowWin("PLG_FightReplay", "UIFightReplayAttackerPanel");

        sprite = attackerPanel.GetComponent <UISprite>();
        PanelUtil.SetPanelAnchors(sprite, UIMananger.Instance.uiLayer.transform, new Vector4(1, 1, 1, 1), new Vector4(-sprite.width, 0, -sprite.height, 0));
        attackerPanel.GetComponent <UIFightReplayAttackerWnd>().UpdateAttackerInfo(null, null);
        //回放战斗面板
        GameObject replayPanel = UIMananger.Instance.ShowWin("PLG_FightReplay", "UIFightReplayPanel");

        panel = replayPanel.GetComponent <UIPanel>();
        panel.baseClipRegion = new Vector4(0, 0, 0, 150);
        replayPanel.transform.localPosition = new Vector3(0, -(Constants.UI_HEIGHT - panel.baseClipRegion.w) * 0.5f, 0);
        panel.clipping = UIDrawCall.Clipping.ConstrainButDontClip;
        PanelUtil.SetPanelAnchors(panel, UIMananger.Instance.uiLayer.transform, new Vector4(0, 1, 0, 0), new Vector4(0, 0, 0, panel.baseClipRegion.w));
        replayPanel.GetComponent <UIFightReplayWnd>().SetFightData();
        //回放倒计时
        GameObject backTimeWin = UIMananger.Instance.ShowWin("PLG_FightReplay", "UIFightReplayBackTimePanel");

        sprite = backTimeWin.GetComponent <UISprite>();
        PanelUtil.SetPanelAnchors(sprite, UIMananger.Instance.uiLayer.transform, new Vector4(0.5f, 0.5f, 1, 1), new Vector4(-sprite.width * 0.5f, sprite.width * 0.5f, -sprite.height, 0));
        backTimeWin.GetComponent <UIFightReplayBackTimeWnd>().SetFightReplayTime();
        EventDispather.AddEventListener(GameEvents.BATTLE_END, OnFightRealEnd);
    }
Beispiel #7
0
    private void OnBattleEnd()
    {
        if (this.IsBattleEnded)
        {
            return;
        }

        this.IsBattleEnded = true;
        GameRecord.OnBattleEnd();

        if (GameWorld.Instance.worldType != WorldType.Replay)
        {
            var replayData = GameRecord.GetRecordData();
            replayData.attacker = attackerData;
            replayData.defender = defenderData;
            new BattleResultCommand(GetBattleResult(), replayData).ExecuteAndSend();
        }
        EventDispather.DispatherEvent(GameEvents.BATTLE_END);

        var attackerEntities = IsoMap.Instance.GetAllEntitiesByOwner(OwnerType.Attacker);

        foreach (var attackerEntity in attackerEntities)
        {
            attackerEntity.Destroy();
        }
    }
Beispiel #8
0
    public override ReqWrapper Execute()
    {
        //占用工人数量
        DataCenter.Instance.FreeWorker += 1;
        EntityModel replaceModel = null;
        if (entity.buildingVO.buildingStatus == BuildingVO.BuildingStatus.Construct)
        {
            replaceModel = entity.model;
            //判断是否是军营
            if (EntityTypeUtil.IsBarracks(entity.model))
            {
                DataCenter.Instance.TotalSpace += entity.model.spaceProvide;
            }
        }
        else if (entity.buildingVO.buildingStatus == BuildingVO.BuildingStatus.Upgrade)//升级
        {
            replaceModel = DataCenter.Instance.FindEntityModelById(entity.model.upgradeId);
            //判断是否是军营
            if (EntityTypeUtil.IsBarracks(entity.model))
            {
                DataCenter.Instance.TotalSpace += (replaceModel.spaceProvide - entity.model.spaceProvide);//军营空间升级
            }
            else if (EntityTypeUtil.IsCenterBuilding(entity.model))
            {
                DataCenter.Instance.Defender.player.baseId = replaceModel.baseId;
            }
        }
        else
        {
            Assert.Fail("building status error!");
        }
        DataCenter.Instance.AddExp(replaceModel.buildExp);

        //替换成建造或者升级完成后的建筑
        entity.buildingVO.buildingStatus = BuildingVO.BuildingStatus.On;
        entity.buildingVO.cid = replaceModel.baseId;
        var newEntity = entity.ReplaceWith(replaceModel, entity.buildingVO);
        ((IsoWorldModeBuilder)GameWorld.Instance.CurrentWorldMode).SelectBuilding(newEntity);

        EventDispather.DispatherEvent(GameEvents.BUILDING_COMPLETE, entity.buildingVO);

        var buildingCompleteReq = new BuildingCompleteReq();
        buildingCompleteReq.sid = sid;
        if (immediately)
        {
            buildingCompleteReq.completeType = BuildingCompleteReq.CompleteType.CompleteImmediately;
            var now = ServerTime.Instance.Now();
            buildingCompleteReq.timestamp = DateTimeUtil.DateTimeToUnixTimestampMS(now);

            int deltaTime = (int)(DateTimeUtil.UnixTimestampMSToDateTime(entity.buildingVO.endTime) - now).TotalSeconds;
            DataCenter.Instance.RemoveResource(ResourceType.Diamond, GameDataAlgorithm.TimeToGem(deltaTime));
        }
        else
        {
            buildingCompleteReq.completeType = BuildingCompleteReq.CompleteType.Normal;
        }
        return new ReqWrapper() { requestType = ReqWrapper.RequestType.BuildingComplete, buildingCompleteReq = buildingCompleteReq };
    }
Beispiel #9
0
    /// <summary>
    /// 在倒计时时间内直接出兵,战斗开始
    /// </summary>
    /// <param name="eventType"></param>
    /// <param name="obj"></param>
    private void OnFightRealBegin(string eventType, object obj)
    {
        EventDispather.RemoveEventListener(GameEvents.BATTLE_SPAWN, OnFightRealBegin);
        EventDispather.DispatherEvent(BACK_TIME_FIGHT_START);
        GameObject backTimeWin = UIMananger.Instance.ShowWin("PLG_Fight", "UIFightBackTimePanel");
        UISprite   sprite      = backTimeWin.GetComponent <UISprite>();

        PanelUtil.SetPanelAnchors(sprite, UIMananger.Instance.uiLayer.transform, new Vector4(0.5f, 0.5f, 1, 1), new Vector4(-sprite.width * 0.5f, sprite.width * 0.5f, -sprite.height, 0));
        backTimeWin.GetComponent <UIFightBackTimeWnd>().SetTimeAndType(2, 180);
    }
 public override void Destroy()
 {
     if (gatherIcon != null)
     {
         gatherIcon.GetComponent <CollectResIconUI>().OnClickEvent -= GatherResource;
         GameObject.Destroy(gatherIcon);
         gatherIcon = null;
     }
     EventDispather.RemoveEventListener(GameEvents.RESOURCE_CHANGE, OnResourceChange);
     base.Destroy();
 }
Beispiel #11
0
 private void OnFightRealEnd(string eventType, object obj)
 {
     EventDispather.RemoveEventListener(GameEvents.BATTLE_END, OnFightRealEnd);
     UIMananger.Instance.CloseWin("UIFightBackTimePanel");
     UIMananger.Instance.CloseWin("UIFightReplayBackTimePanel");
     if (GameWorld.Instance.worldType == WorldType.Battle)
     {
         DelayManager.Instance.AddDelayCall(ShowFightResultWin, 1.2f);
     }
     else if (GameWorld.Instance.worldType == WorldType.Replay)
     {
         DelayManager.Instance.AddDelayCall(ShowFightReplayResultWin, 1.2f);
     }
 }
 public int storage;//剩余量
 public override void Init()
 {
     if (GameWorld.Instance.worldType != WorldType.Home || Entity.buildingVO.buildingStatus != BuildingVO.BuildingStatus.On)
     {
         enabled = false;
     }
     else
     {
         EventDispather.AddEventListener(GameEvents.RESOURCE_CHANGE, OnResourceChange);
     }
     UpdateState(DateTimeUtil.UnixTimestampMSToDateTime(Entity.buildingVO.resourceBuildingVO.lastGatherTime), storage);
     showingGatherIcon = false;
     base.Init();
 }
Beispiel #13
0
    public void AddExp(int exp)
    {
        Defender.player.experience += exp;
        EventDispather.DispatherEvent(GameEvents.EXP_CHANGE);
        RankModel current, next;

        FindRankModel(RankType.Level, Defender.player.experience, out current, out next);
        var newlevel = int.Parse(current.name);

        if (newlevel > Defender.player.level)
        {
            Defender.player.level = newlevel;
            EventDispather.DispatherEvent(GameEvents.LEVEL_UP);
        }
    }
Beispiel #14
0
    // Use this for initialization
    void Start()
    {
        for (int i = 0; i < uilist.Length; i++)
        {
            string name = ((GameObject)uilist[i]).name;

            ui[name] = (GameObject)uilist[i];
        }

        ShowSingleUI("ControllUI");

        EventDispather.AddEventListener(EventName.UI_SHOW, OnShowUI);
        EventDispather.AddEventListener(EventName.UI_SHOW_SINGLE, OnShowUI);

        SoundManager.PlayMusic(3);
    }
Beispiel #15
0
    /// <summary>
    /// 改变技能shop
    /// </summary>
    /// <param name="skillId">当前升级的技能id</param>
    public void ChangeSkillShop(int skillId)
    {
        EntityModel skillModel = FindEntityModelById(skillId);
        int         index      = Defender.player.skillShop.IndexOf(skillId);

        if (index >= 0)
        {
            Defender.player.skillShop[index] = skillModel.upgradeId;
            foreach (SkillVO skillVO in Defender.skills)
            {
                if (skillVO.cid == skillId)
                {
                    skillVO.cid = skillModel.upgradeId;
                }
            }
            EventDispather.DispatherEvent(GameEvents.SKILL_UP, skillId);
        }
    }
Beispiel #16
0
    private void ChangeArmyExp(ArmyVO army)
    {
        //判断当前的兵能不能加经验
        if (!ItemOperationManager.Instance.IsItemCanLevelUp(army.cid))
        {
            return;
        }
        List <ArmyExpVO> list      = Defender.player.armyShop;
        EntityModel      nextModel = ModelUtil.GetNextLevelModel(army.cid);
        //升级到的Id
        int levelUpId = 0;

        foreach (ArmyExpVO expVo in list)
        {
            if (expVo.cid == army.cid)
            {
                expVo.exp += army.amount;
                //可能跳跃升级
                while (null != nextModel && expVo.exp >= nextModel.costResourceCount)
                {
                    expVo.cid = nextModel.baseId;
                    levelUpId = nextModel.baseId;
                    nextModel = ModelUtil.GetNextLevelModel(nextModel.baseId);
                }
                break;
            }
        }
        if (levelUpId != 0)
        {
            foreach (var armyVo in Defender.armies)
            {
                if (armyVo.cid == army.cid)
                {
                    armyVo.cid = levelUpId;
                    break;
                }
            }
            EventDispather.DispatherEvent(GameEvents.SOLDIER_UP, army.cid);
        }
        else
        {
            EventDispather.DispatherEvent(GameEvents.SOLDIER_COUNT_CHANGE, army.cid);
        }
    }
Beispiel #17
0
 public void BackTimeOver(int type)
 {
     if (BACK_TIME_FIGHT_PREPARE == type)
     {
         //战斗准备期结束
         GameObject backTimeWin = UIMananger.Instance.ShowWin("PLG_Fight", "UIFightBackTimePanel");
         UISprite   sprite      = backTimeWin.GetComponent <UISprite>();
         PanelUtil.SetPanelAnchors(sprite, UIMananger.Instance.uiLayer.transform, new Vector4(0.5f, 0.5f, 1, 1), new Vector4(-sprite.width * 0.5f, sprite.width * 0.5f, -sprite.height, 0));
         backTimeWin.GetComponent <UIFightBackTimeWnd>().SetTimeAndType(2, 180);
         EventDispather.DispatherEvent(BACK_TIME_FIGHT_START);
         //战斗默认开始了
         BattleManager.Instance.StartBattle();
         //倒计时正常结束,不需要监听本事件
         EventDispather.RemoveEventListener(GameEvents.BATTLE_SPAWN, OnFightRealBegin);
     }
     else if (BACK_TIME_FIGHT_OVER == type)
     {
         //战斗结束
         UIMananger.Instance.CloseWin("UIBackTimePanel");
         BattleManager.Instance.ForceBattleEnd();
         ShowFightResultWin();
     }
 }
Beispiel #18
0
    public void AddResource(ResourceType resourceType, int resourceCount, OwnerType owner = OwnerType.Defender)
    {
        CampVO camp = owner == OwnerType.Attacker ? Attacker : Defender;

        foreach (var resourceVo in camp.player.resources)
        {
            if (resourceVo.resourceType == resourceType)
            {
                resourceVo.resourceCount += resourceCount;
                if (resourceVo.resourceCount < 0)
                {
                    resourceVo.resourceCount = 0;
                }
                if (owner == OwnerType.Defender)
                {
                    GameWorld.Instance.AverageResourceStorageComponents(resourceType);
                    EventDispather.DispatherEvent(GameEvents.RESOURCE_CHANGE, resourceVo);
                }
                return;
            }
        }
        Assert.Fail("should not reach here");
    }
Beispiel #19
0
    /// <summary>
    /// 显示战斗的UI
    /// </summary>
    public void ShowBattleUI()
    {
        UIMananger.Instance.CloseWinByType(UICloseOrHideType.CLOSE_WORLD_TYPE_BATTLE);
        UIPanel  panel;
        UISprite sprite;
        //战斗界面下方窗体
        GameObject fightPanel = UIMananger.Instance.ShowWin("PLG_Fight", "UIFightPanel");

        panel = fightPanel.GetComponent <UIPanel>();
        panel.baseClipRegion = new Vector4(0, 0, 0, 150);
        fightPanel.transform.localPosition = new Vector3(0, -(Constants.UI_HEIGHT - panel.baseClipRegion.w) * 0.5f, 0);
        panel.clipping = UIDrawCall.Clipping.ConstrainButDontClip;
        PanelUtil.SetPanelAnchors(panel, UIMananger.Instance.uiLayer.transform, new Vector4(0, 1, 0, 0), new Vector4(0, 0, 0, panel.baseClipRegion.w));
        fightPanel.GetComponent <UIFightWnd>().SetFightData();
        //战斗内部信息
        GameObject fightInfo = UIMananger.Instance.ShowWin("PLG_Fight", "UIFightInfoPanel");

        sprite = fightInfo.GetComponent <UISprite>();
        PanelUtil.SetPanelAnchors(sprite, UIMananger.Instance.uiLayer.transform, new Vector4(0, 0, 1, 1), new Vector4(0, sprite.width, -sprite.height, 0));
        fightInfo.GetComponent <UIFightInfoWnd>().UpdateFightInfo(null, null);
        //战斗中掠夺资源
        GameObject personMoneyWin = UIMananger.Instance.ShowWin("PLG_MainUI", "UIPersonMoneyPanel");

        sprite = personMoneyWin.GetComponent <UISprite>();
        PanelUtil.SetPanelAnchors(sprite, UIMananger.Instance.uiLayer.transform, new Vector4(1, 1, 1, 1), new Vector4(-sprite.width, 0, -sprite.height, 0));
        personMoneyWin.GetComponent <UIPersonMoneyWnd>().SetPlayerMoney(OwnerType.Attacker);
        //战斗计时
        GameObject backTimeWin = UIMananger.Instance.ShowWin("PLG_Fight", "UIFightBackTimePanel");

        sprite = backTimeWin.GetComponent <UISprite>();
        PanelUtil.SetPanelAnchors(sprite, UIMananger.Instance.uiLayer.transform, new Vector4(0.5f, 0.5f, 1, 1), new Vector4(-sprite.width * 0.5f, sprite.width * 0.5f, -sprite.height, 0));
        backTimeWin.GetComponent <UIFightBackTimeWnd>().SetTimeAndType(BACK_TIME_FIGHT_PREPARE, 10);
        EventDispather.AddEventListener(GameEvents.BATTLE_SPAWN, OnFightRealBegin);
        EventDispather.AddEventListener(GameEvents.BATTLE_END, OnFightRealEnd);
        hasUseArmy = false;
    }
    public override ReqWrapper Execute()
    {
        var gold = new ResourceVO()
        {
            resourceType  = ResourceType.Gold,
            resourceCount = battleResult.rewardGoldByCrownLevel
        };
        var oil = new ResourceVO()
        {
            resourceType  = ResourceType.Oil,
            resourceCount = battleResult.rewardOilByCrownLevel
        };

        DataCenter.Instance.AddResource(gold, OwnerType.Attacker);
        DataCenter.Instance.AddResource(oil, OwnerType.Attacker);
        EventDispather.DispatherEvent(GameEvents.STOLEN_RESOURCE, gold);
        EventDispather.DispatherEvent(GameEvents.STOLEN_RESOURCE, oil);
        DataCenter.Instance.AddCrown(battleResult.rewardCrown, OwnerType.Attacker);
        for (int i = DataCenter.Instance.Attacker.armies.Count - 1; i >= 0; i--)
        {
            if (DataCenter.Instance.Attacker.armies[i].amount == 0)
            {
                DataCenter.Instance.Attacker.armies.RemoveAt(i);
            }
        }

        return(new ReqWrapper()
        {
            requestType = ReqWrapper.RequestType.BattleResult,
            battleResultReq = new BattleResultReq()
            {
                battleResultVO = battleResult,
                battleReplayVO = battleReplay
            }
        });
    }
Beispiel #21
0
 public override void Destroy()
 {
     EventDispather.RemoveEventListener(GameEvents.TRAP_REFILL, OnTrapRefill);
     base.Destroy();
 }
Beispiel #22
0
    /// <summary>
    /// 有单位死亡了
    /// </summary>
    /// <param name="entity"></param>
    public void OnEntityDestroy(TileEntity entity)
    {
        //如果死亡的是建筑
        if (EntityTypeUtil.IsAnyNonWallBuilding(entity.entityType))
        {
            defenderBuildingCount--;
            DestroyBuildingPercent = (float)(totalDefenderBuildingCount - defenderBuildingCount) / totalDefenderBuildingCount;
            //摧毁50% 获得一颗星
            if (!hasGotHalfDestroyStar && DestroyBuildingPercent > 0.5f)
            {
                hasGotHalfDestroyStar = true;
                BattleStar++;
            }
            Debug.Log("摧毁:" + DestroyBuildingPercent + "%");

            //摧毁基地 获得一颗星
            if (EntityTypeUtil.IsCenterBuilding(entity.model))
            {
                BattleStar++;
            }
            //摧毁100% 获得一颗星
            if (defenderBuildingCount == 0)
            {
                BattleStar++;
            }

            EventDispather.DispatherEvent(GameEvents.BATTLE_PROGRESS_CHANGE);
        }
        else if (entity.GetOwner() == OwnerType.Attacker && EntityTypeUtil.IsAnyActor(entity.entityType))
        {
            attackerArmyCount--;
            if (EntityTypeUtil.IsCurer(entity.model))
            {
                attackerCurerCount--;
            }
        }
        else if (entity.GetOwner() == OwnerType.Defender)
        {
            if (EntityTypeUtil.IsAnyActor(entity.entityType))
            {
                if (entity.Friendly)
                {
                    var found = false;
                    foreach (var killedDefenderDonatedArmy in killedDefenderDonatedArmies)
                    {
                        if (killedDefenderDonatedArmy.cid == entity.model.baseId)
                        {
                            killedDefenderDonatedArmy.amount++;
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        killedDefenderDonatedArmies.Add(new ArmyVO()
                        {
                            amount = 1, cid = entity.model.baseId
                        });
                    }
                }
            }
            else if (EntityTypeUtil.IsAnyTrap(entity.model))
            {
                brokenTraps.Add(entity.buildingVO.sid);
            }
        }
        CheckBattleEnd();
    }
Beispiel #23
0
 public static void HeroDead(Hero hero)
 {
     hero.StopMoving();
     EventDispather.DispatchEvent(new GameEvent(EventName.UI_SHOW_SINGLE, "GameOverUI"));
 }
Beispiel #24
0
    public static void Update()
    {
        switch (state)
        {
        case BattleState.STATE_LOADING:
            state = BattleState.STATE_BUILDING;
            break;

        case BattleState.STATE_BUILDING:
            battle.SetExitPoint(false);
            battle.SetEnterPoint(true);
            Clear();
            Build();
            break;

        case BattleState.STATE_START_ANIMATION:
            int      groundId     = (int)copyConfig.maps[groundIndex];
            JsonData groundConfig = Config.GetInstance().GetGroundConfig(groundId);

            if (hero == null)
            {
                AddHero(groundConfig);
            }
            else
            {
                hero.SetStartPosition((int)groundConfig["start_x"], (int)groundConfig["start_y"]);
            }

            hero.currentDirection = MoveDirection.UP;

            Follower f = hero.follower;

            while (f != null)
            {
                f.ResetPostion();
                f.SetDirection(hero.currentDirection);
                f.SetPosition(hero.transform.localPosition);
                f.gameObject.SetActive(true);

                f.SetNextPosition(hero.transform.localPosition);

                f = f.follower;
            }

            hero.audio.clip = null;
            hero.gameObject.SetActive(true);
            hero.StopAnimation();
            hero.StopMoving();

            hero.Invoke("PlayMoving", 2);
            hero.Invoke("PlayAnimation", 2);
            battle.Invoke("HideEnterPoint", 1);

            state = BattleState.STATE_BATTLING;
            break;

        case BattleState.STATE_BATTLING:
            if ((int)timeLine < (int)(timeLine + Time.deltaTime))
            {
                CheckTimePoint();
            }

            timeLine += Time.deltaTime;
            SkillManager.Update();
            break;

        case BattleState.STATE_WIN:
            groundIndex++;

            if (groundIndex >= copyConfig.maps.Count)
            {
                hero.StopMoving();
                EventDispather.DispatchEvent(new GameEvent(EventName.UI_SHOW_SINGLE, "WinUI"));
            }
            else
            {
                state = BattleState.STATE_TO_NEXT;
                battle.SetExitPoint(true);
            }

            break;

        case BattleState.STATE_END_ANIMATION:
            state = BattleState.STATE_BUILDING;
            break;

        case BattleState.STATE_TO_NEXT:
            HeroAutoMove();
            break;

        case BattleState.STATE_LOSE:
            break;
        }
    }
Beispiel #25
0
    public override void Init()
    {
        base.Init();

        EventDispather.AddEventListener(GameEvents.SKILL_UP, OnSkillUpEvent);
    }
Beispiel #26
0
 public override void Destroy()
 {
     EventDispather.RemoveEventListener(GameEvents.SKILL_UP, OnSkillUpEvent);
     base.Destroy();
 }
Beispiel #27
0
    public void PlayerPlaceSoldierOrSkill(int entityId, int x, int y, bool record = true)
    {
        if (!IsBattleStarted)
        {
            return;
        }
        var model = DataCenter.Instance.FindEntityModelById(entityId);

        //是否是使用的援军
        if (entityId == Constants.DENOTED_ARMY_ID)
        {
            if (!useDonatedArmy)
            {
                if (IsoMap.Instance.CanPlaceSoldier(x, y))
                {
                    useDonatedArmy = true;
                    Debug.Log("使用的援军");
                    //  战斗模式 [录像] 记录操作数据
                    if (record)
                    {
                        GameRecord.RecordPlaceSoldier(x, y, Constants.DENOTED_ARMY_ID);
                    }
                    var spawnHelper = new SpawnDonatedArmyHelper(DataCenter.Instance.Attacker.donatedArmies.Clone(), x, y);
                    UpdateManager.Instance.AddUpdate(spawnHelper);

                    DataCenter.Instance.Attacker.donatedArmies.Clear();
                }
                else
                {
                    GameTipsManager.Instance.ShowGameTips(EnumTipsID.Fight_10301);
                    IsoMap.Instance.ShowGuardAreaMap(true);
                }
            }
        }
        else if (EntityTypeUtil.IsSkill(model))
        {
            if (IsoMap.Instance.CanPlaceSkill(x, y))
            {
                foreach (var skillVo in DataCenter.Instance.Attacker.skills)
                {
                    if (skillVo.cid == model.baseId && skillVo.amount > 0)
                    {
                        if (record)
                        {
                            GameRecord.RecordPlaceSoldier(x, y, model.baseId);
                        }
                        GameSkillManager.Instance.AddSkill(model, x, y);
                        skillVo.amount--;
                        break;
                    }
                }
            }
            else
            {
                GameTipsManager.Instance.ShowGameTips(EnumTipsID.Fight_10301);
            }
        }
        else
        {
            if (IsoMap.Instance.CanPlaceSoldier(x, y))
            {
                foreach (var armyVo in DataCenter.Instance.Attacker.armies)
                {
                    if (armyVo.cid == model.baseId && armyVo.amount > 0)
                    {
                        //  战斗模式 [录像] 记录操作数据
                        if (record)
                        {
                            GameRecord.RecordPlaceSoldier(x, y, model.baseId);
                        }
                        //  创建对象
                        IsoMap.Instance.CreateEntityAt(OwnerType.Attacker, model.baseId, x, y);
                        armyVo.amount--;
                        break;
                    }
                }
            }
            else
            {
                GameTipsManager.Instance.ShowGameTips(EnumTipsID.Fight_10301);
                IsoMap.Instance.ShowGuardAreaMap(true);
            }
        }
        EventDispather.DispatherEvent(GameEvents.BATTLE_SPAWN, entityId);
    }
Beispiel #28
0
 public void SetBattleHistories(List <BattleResultVO> attackHistories, List <BattleResultVO> defenseHistories)
 {
     this.attackHistories  = attackHistories;
     this.defenseHistories = defenseHistories;
     EventDispather.DispatherEvent(GameEvents.BATTLE_HISTORY_LOADED);
 }