Example #1
0
    private void CreateViewActor(int cid)
    {
        var model  = DataCenter.Instance.FindEntityModelById(cid);
        var entity = TileEntity.Create(OwnerType.Defender, model);

        entity.SetTilePosition(Entity.GetTilePos());
        IsoMap.Instance.DelayAddEntity(entity);
    }
Example #2
0
    public void Spawn(EntityModel model, int x, int y)
    {
        //  创建对象(设置友军/援军标记)
        var tileEntity = TileEntity.Create(Entity.GetOwner(), model, true);

        tileEntity.SetTilePosition(new TilePoint(x, y));

        //  延迟添加到地图上(避免迭代器损坏)
        IsoMap.Instance.DelayAddEntity(tileEntity);
    }
Example #3
0
    public TileEntity CreateEntityAt(OwnerType owner, int entityId, int x, int y)
    {
        var model = DataCenter.Instance.FindEntityModelById(entityId);
        //  创建对象
        var tileEntity = TileEntity.Create(owner, model);

        tileEntity.SetTilePosition(new TilePoint(x, y));

        //  添加到地图上
        ForceAddEntity(tileEntity);
        return(tileEntity);
    }
Example #4
0
    /// <summary>
    /// 购买建筑
    /// </summary>
    /// <param name="cid"></param>
    public void BuyBuilding(int cid)
    {
        var builder = GameWorld.Instance.CurrentWorldMode as IsoWorldModeBuilder;

        Assert.Should(builder != null, "BuyBuilding only work in Homeland");
        if (builder != null)
        {
            var building = DataCenter.Instance.FindEntityModelById(cid);
            Assert.Should(building != null);
            var tileEntity = TileEntity.Create(OwnerType.Defender, building);
            tileEntity.view.Init();
            builder.SetBuildingObject(tileEntity);
        }
    }
Example #5
0
    void OnGUI()
    {
        return;

        if (GameWorld.Instance.Loading)
        {
            return;
        }

        switch (GameWorld.Instance.worldType)
        {
        case WorldType.Home:
        {
            //if (GUI.Button(new Rect(120, 400, 50, 50), "出兵"))
            //{
            //    GameWorld.Instance.ChangeLoading(WorldType.Battle);
            //    return;
            //}
            //  o(╯□╰)o
            if (GUI.Button(new Rect(120, 500, 50, 50), "回放"))
            {
                GameWorld.Instance.ChangeLoading(WorldType.Replay);
                return;
            }
        }
        break;

        case WorldType.Battle:
        {
            if (GUI.Button(new Rect(120, 400, 50, 50), "回营"))
            {
                replaySpeed    = 1;
                Time.timeScale = replaySpeed;
                //GameWorld.Instance.BackToMyCamp();
                return;
            }
        }
        break;

        case WorldType.Replay:
        {
            if (GUI.Button(new Rect(120, 400, 50, 50), "回营"))
            {
                replaySpeed    = 1;
                Time.timeScale = replaySpeed;
                //GameWorld.Instance.BackToMyCamp();
                return;
            }
            if (GUI.Button(new Rect(200, 400, 50, 50), "x" + replaySpeed))
            {
                replaySpeed *= 2;
                if (replaySpeed > 8)
                {
                    replaySpeed = 1;
                }
                Time.timeScale = replaySpeed;
            }
            if (GUI.Button(new Rect(280, 400, 50, 50), paused ? ">" : "||"))
            {
                paused = !paused;
                if (paused)
                {
                    oldReplaySpeed = replaySpeed;
                    replaySpeed    = 0;
                }
                else
                {
                    replaySpeed = oldReplaySpeed;
                }
                Time.timeScale = replaySpeed;
            }
        }
        break;

        case WorldType.Visit:
            break;

        default:
            break;
        }

        if (GameWorld.Instance.worldType == WorldType.Home)
        {
            if (GUI.Button(new Rect(Screen.width - 200, Screen.height - 200, 50, 50), "建造"))
            {
                var model      = DataCenter.Instance.FindEntityModelByResourceName("HtowerA11");
                var tileEntity = TileEntity.Create(OwnerType.Defender, model);
                tileEntity.Init();
                ((IsoWorldModeBuilder)GameWorld.Instance.CurrentWorldMode).SetBuildingObject(tileEntity);
            }
            if (GUI.Button(new Rect(Screen.width - 120, Screen.height - 200, 50, 50), "陷阱"))
            {
                var model = DataCenter.Instance.FindEntityModelByResourceName("HtowerA11");
                model.entityType = EntityType.Trap;
                model.range      = 1.5f;
                var tileEntity = TileEntity.Create(OwnerType.Defender, model);
                tileEntity.Init();
                ((IsoWorldModeBuilder)GameWorld.Instance.CurrentWorldMode).SetBuildingObject(tileEntity);
            }
            if (GUI.Button(new Rect(Screen.width - 200, Screen.height - 100, 50, 50), "墙"))
            {
                var wallModel  = DataCenter.Instance.FindEntityModelByResourceName("HwallB01");
                var tileEntity = TileEntity.Create(OwnerType.Defender, wallModel);
                tileEntity.Init();
                (GameWorld.Instance.CurrentWorldMode as IsoWorldModeBuilder).SetBuildingObject(tileEntity, true);
            }
            if (GUI.Button(new Rect(Screen.width - 120, Screen.height - 100, 50, 50), "军营"))
            {
                var camp       = DataCenter.Instance.FindEntityModelByResourceName("HhouseK01");
                var tileEntity = TileEntity.Create(OwnerType.Defender, camp);
                tileEntity.Init();
                (GameWorld.Instance.CurrentWorldMode as IsoWorldModeBuilder).SetBuildingObject(tileEntity, true);
            }
            if (GUI.Button(new Rect(Screen.width - 200, Screen.height - 500, 100, 100), "保存村庄"))
            {
                var campVO = DataCenter.Instance.Defender;
                System.IO.MemoryStream stream = new System.IO.MemoryStream();
                ProtoBuf.Serializer.Serialize <ProtoBuf.IExtensible>(stream, campVO);
                System.Byte[] bytes = stream.ToArray();
                using (FileStream fs = new FileStream(Application.streamingAssetsPath + "/last_save_village.pbd", FileMode.Create))
                {
                    using (BinaryWriter writer = new BinaryWriter(fs))
                    {
                        writer.Write(bytes);
                    }
                }
                Debug.Log("Saved");
            }
            if (GUI.Button(new Rect(Screen.width - 200, Screen.height - 400, 100, 100), "加载村庄"))
            {
                byte[] bytes  = File.ReadAllBytes(Application.streamingAssetsPath + "/last_save_village.pbd");
                var    stream = new MemoryStream(bytes);
                var    campVO = ProtoBuf.Serializer.Deserialize <CampVO>(stream);
                GameWorld.Instance.Create(WorldType.Home, campVO);
            }
            if (GUI.Button(new Rect(Screen.width - 100, Screen.height - 400, 100, 100), "加载村庄-战斗"))
            {
                byte[] bytes  = File.ReadAllBytes(Application.streamingAssetsPath + "/last_save_village.pbd");
                var    stream = new MemoryStream(bytes);
                var    campVO = ProtoBuf.Serializer.Deserialize <CampVO>(stream);
                GameWorld.Instance.Create(WorldType.Battle, campVO, campVO);
            }
        }
        else if (GameWorld.Instance.worldType == WorldType.Battle)
        {
            if (GUI.Button(new Rect(Screen.width - 200, Screen.height - 240, 120, 50), "技能"))
            {
                //  TODO:
                GameSkillManager.Instance.AddSkill(null, 40, 40);
            }
            if (GUI.Button(new Rect(Screen.width - 200, Screen.height - 300, 120, 50), "提交录像"))
            {
                GameRecord.Commit();
            }
            if (GUI.Button(new Rect(20, Screen.height - 200, 100, 50), "进攻-甲壳虫"))
            {
                var actor = DataCenter.Instance.FindEntityModelByResourceName("HsoldierD01");
                //actor.subType = "Esoldier"; // 炸弹人属性
                //actor.hitEffectName = "Effect1";
                //actor.splashRange = 3.0f;
                //actor.additionDamageRatio = 100;
                (GameWorld.Instance.CurrentWorldMode as IsoWorldModeAttack).SetSpawnId(actor.baseId);
            }
            if (GUI.Button(new Rect(20, Screen.height - 270, 100, 50), "进攻-医疗兵"))
            {
                var actor = new EntityModel();
                actor.raceType        = RaceType.Predator;
                actor.entityType      = EntityType.ActorFly;
                actor.nameForResource = "PsoldierB01";
                actor.hp         = 100000;
                actor.speed      = 2.5f;
                actor.damage     = 10;
                actor.rate       = 3.0f;
                actor.bulletType = EntityBulletType.Direct; //  直接伤害

                actor.cure        = 10;                     //  医疗兵相关属性
                actor.cureRange   = 80;
                actor.range       = 10;
                actor.splashRange = 10;

                (GameWorld.Instance.CurrentWorldMode as IsoWorldModeAttack).SetSpawnId(actor.baseId);
            }
        }
    }
Example #6
0
    public void Create(WorldType worldType, CampVO defender = null, CampVO attacker = null, BattleReplayVO replayVO = null)
    {
        this.worldType = worldType;

        IsoMap.Instance.Clear();
        GameBulletManager.Instance.Init();
        GameEffectManager.Instance.Init();
        GameSkillManager.Instance.Init();
        UpdateManager.Instance.Clear();
        DelayManager.Instance.Init();
        BattleManager.Instance.Init();
        PoolManager.Instance.Clear();
        ResourceManager.Instance.ClearCache();

        //  初始化数据
        if (defender != null)
        {
            DataCenter.Instance.Defender = defender;
        }
        if (attacker != null)
        {
            DataCenter.Instance.Attacker = attacker;
        }

        //  REMARK:录像模式或回放模式从这里开始处理(之前的模块释放完毕,开始放置建筑之前。)
        if (worldType == WorldType.Battle)
        {
            GameRecord.StartRecord();
        }
        else if (worldType == WorldType.Replay)
        {
            Assert.Should(replayVO != null);
            DataCenter.Instance.Attacker = replayVO.attacker;
            DataCenter.Instance.Defender = replayVO.defender;
            GameRecord.StartReplay(replayVO);
        }

        //  添加建筑
        for (int i = 0; i < DataCenter.Instance.Defender.buildings.Count; i++)
        {
            var buildingVO  = DataCenter.Instance.Defender.buildings[i];
            var entityModel = DataCenter.Instance.FindEntityModelById(buildingVO.cid);
            Assert.Should(entityModel != null);
            var tileEntity = TileEntity.Create(OwnerType.Defender, entityModel);
            tileEntity.buildingVO = buildingVO;
            tileEntity.SetTilePosition(new TilePoint(buildingVO.x, buildingVO.y));
            IsoMap.Instance.ForceAddEntity(tileEntity);
        }

        //  添加工人,士兵(仅在建造模式下)
        if (worldType == WorldType.Home)
        {
            foreach (var armyVo in DataCenter.Instance.Defender.armies)
            {
                for (int i = 0; i < armyVo.amount; i++)
                {
                    var actor      = DataCenter.Instance.FindEntityModelById(armyVo.cid);
                    var tileEntity = TileEntity.Create(OwnerType.Defender, actor);
                    tileEntity.SetTilePosition(new TilePoint(0, 0));
                    IsoMap.Instance.ForceAddEntity(tileEntity);
                }
            }
            //  TODO:临时
            for (int i = 0; i < DataCenter.Instance.Defender.player.maxWorker; i++)
            {
                var actor      = DataCenter.Instance.FindEntityModelByResourceName("Pworker");
                var tileEntity = TileEntity.Create(OwnerType.Defender, actor);
                tileEntity.SetTilePosition(new TilePoint(5, 5));
                IsoMap.Instance.ForceAddEntity(tileEntity);
                tileEntity.HideEntity();
            }

            //计算最大人口
            DataCenter.Instance.TotalSpace = 0;
            foreach (var buildingVo in DataCenter.Instance.Defender.buildings)
            {
                var model = DataCenter.Instance.FindEntityModelById(buildingVo.cid);
                if (EntityTypeUtil.IsBarracks(model))
                {
                    DataCenter.Instance.TotalSpace += model.spaceProvide;
                }
            }
            //计算已使用人口
            DataCenter.Instance.SpaceUsed = 0;
            foreach (var armyVo in DataCenter.Instance.Defender.armies)
            {
                var model = DataCenter.Instance.FindEntityModelById(armyVo.cid);
                DataCenter.Instance.SpaceUsed += model.spaceUse * armyVo.amount;
            }
        }

        //把资源平均分配到资源库
        AverageResourceStorageComponents(ResourceType.Gold);
        AverageResourceStorageComponents(ResourceType.Oil);

        switch (worldType)
        {
        case WorldType.Battle:
            IsoMap.Instance.InitGuardAreaMap();
            IsoMap.Instance.ShowGuardAreaMap(false);
            CurrentWorldMode = new IsoWorldModeAttack();
            BattleManager.Instance.PreStartBattle();
            BattleUIManager.Instance.ShowBattleUI();
            break;

        case WorldType.Replay:
            CurrentWorldMode = new IsoWorldModeReplay();
            BattleManager.Instance.PreStartBattle();
            BattleManager.Instance.StartBattle();       //  TODO:暂时先放这里
            BattleUIManager.Instance.ShowReplayUI();
            break;

        case WorldType.Visit:
            CurrentWorldMode = new IsoWorldModeVisit();
            break;

        case WorldType.Home:
            CurrentWorldMode = new IsoWorldModeBuilder();
            HomeLandManager.Instance.ShowMyHomeLandUI();
            break;
        }
    }
Example #7
0
 /// <summary>
 /// 建造 确认 or 取消
 /// </summary>
 /// <param name="confirm"></param>
 private void OnBuildConfirm(bool confirm)
 {
     if (confirm)
     {
         if (!IsoMap.Instance.CanPlaceBuilding(currentBuilding.GetTilePos().x, currentBuilding.GetTilePos().y,
                                               currentBuilding.width, currentBuilding.height))
         {
             return;//TODO alert sound
         }
         //send to server
         GameManager.Instance.RequestBuyBuilding(currentBuilding);
         if (isConstructMulti)
         {
             TilePoint?suggestPoint = null;
             if (lastPoint != null)
             {
                 var delta = currentBuilding.GetTilePos() - lastPoint.Value;
                 if (Mathf.Abs(delta.x) + Mathf.Abs(delta.y) == currentBuilding.width) //只有在挨着的时候才处理
                 {
                     var newPoint = currentBuilding.GetTilePos() + delta;
                     if (IsoMap.Instance.CanPlaceBuilding(newPoint.x, newPoint.y, currentBuilding.width,
                                                          currentBuilding.height))
                     {
                         suggestPoint = newPoint;
                     }
                 }
             }
             if (suggestPoint == null && currentBuilding.model.entityType == EntityType.Wall)
             {
                 //判断当前建筑四周是否有墙
                 var currPoint = currentBuilding.GetTilePos();
                 if (IsoMap.Instance.IsWallStrict(currPoint.x - 2, currPoint.y))
                 {
                     suggestPoint = SuggestPosition(currPoint + new TilePoint(2, 0));
                 }
                 else if (IsoMap.Instance.IsWallStrict(currPoint.x + 2, currPoint.y))
                 {
                     suggestPoint = SuggestPosition(currPoint + new TilePoint(-2, 0));
                 }
                 else if (IsoMap.Instance.IsWallStrict(currPoint.x, currPoint.y - 2))
                 {
                     suggestPoint = SuggestPosition(currPoint + new TilePoint(0, 2));
                 }
                 else if (IsoMap.Instance.IsWallStrict(currPoint.x, currPoint.y + 2))
                 {
                     suggestPoint = SuggestPosition(currPoint + new TilePoint(0, -2));
                 }
             }
             if (suggestPoint == null)
             {
                 suggestPoint = SuggestPosition(currentBuilding.GetTilePos());
             }
             lastPoint = currentBuilding.GetTilePos();
             var tileEntity = TileEntity.Create(OwnerType.Defender, currentBuilding.model);
             tileEntity.Init();
             BuildCompleteCleanUp();//清除上一次的建造
             SetBuildingObject(tileEntity, isConstructMulti, suggestPoint);
         }
         else
         {
             lastPoint = currentBuilding.GetTilePos();
             BuildCompleteCleanUp();
         }
     }
     else
     {
         currentBuilding.Destroy();
         BuildCompleteCleanUp();
     }
 }