Ejemplo n.º 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));
    }
Ejemplo n.º 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);
                    }
                }
            }
        }
    }
Ejemplo n.º 3
0
 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,
         }
     });
 }
Ejemplo n.º 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);
    }
Ejemplo n.º 5
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();
        }
    }
Ejemplo n.º 6
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 };
    }
Ejemplo n.º 7
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);
    }
Ejemplo n.º 8
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);
        }
    }
Ejemplo n.º 9
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);
        }
    }
Ejemplo n.º 10
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);
        }
    }
Ejemplo n.º 11
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");
    }
Ejemplo n.º 12
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();
     }
 }
Ejemplo n.º 13
0
    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
            }
        });
    }
Ejemplo n.º 14
0
 public void SetBattleHistories(List <BattleResultVO> attackHistories, List <BattleResultVO> defenseHistories)
 {
     this.attackHistories  = attackHistories;
     this.defenseHistories = defenseHistories;
     EventDispather.DispatherEvent(GameEvents.BATTLE_HISTORY_LOADED);
 }
Ejemplo n.º 15
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);
    }
Ejemplo n.º 16
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();
    }