예제 #1
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 };
    }
예제 #2
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();
    }