Exemple #1
0
    /// <summary>
    /// create req object
    /// </summary>
    /// <returns></returns>
    public BaseReq CreateRequest()
    {
        var request = new BaseReq();

        request.authToken  = DataCenter.Instance.authToken;
        request.timestamp  = ServerTime.Instance.GetTimestamp();
        request.sequenceId = DataCenter.Instance.CreateNextRequestSequenceId();
        if (lastData == null || lastData.player.userId == 0)
        {
            request.before = DataCenter.Instance.originDefenderData;//TODO remove when release
        }
        else
        {
            request.before = lastData;
        }
        request.reqWrapper = Execute();
        if (GameWorld.Instance.worldType == WorldType.Battle)
        {
            request.after = ProtoBuf.Serializer.DeepClone(DataCenter.Instance.Attacker);//TODO remove when release
        }
        else
        {
            request.after = ProtoBuf.Serializer.DeepClone(DataCenter.Instance.Defender);//TODO remove when release
        }
        lastData = request.after;
        return(request);
    }
Exemple #2
0
    public void SetHomelandData(CampVO camp)
    {
        Defender = camp;

        if (camp.player.userId == myUserId)//保存的数据
        {
            Attacker = camp;
        }
    }
Exemple #3
0
    public int GetResource(ResourceType type, OwnerType owner = OwnerType.Defender)
    {
        CampVO camp = owner == OwnerType.Attacker ? Attacker : Defender;

        foreach (var resourceVo in camp.player.resources)
        {
            if (resourceVo.resourceType == type)
            {
                return(resourceVo.resourceCount);
            }
        }
        return(0);
    }
Exemple #4
0
    /// <summary>
    /// 战斗开始
    /// </summary>
    public void StartBattle()
    {
        if (IsBattleStarted)
        {
            return;
        }
        IsBattleStarted = true;
        IsoMap.Instance.HideGuardAreaMap();

        //计算每个建筑的百分比
        var allEntities = IsoMap.Instance.GetAllEntitiesByOwner(OwnerType.Defender);

        foreach (var tileEntity in allEntities)
        {
            if (EntityTypeUtil.IsAnyNonWallBuilding(tileEntity.entityType))
            {
                ++defenderBuildingCount;
            }
        }
        totalDefenderBuildingCount = defenderBuildingCount;

        //计算士兵数量
        foreach (var armyVo in DataCenter.Instance.Attacker.armies)
        {
            attackerArmyCount += armyVo.amount;

            var model = DataCenter.Instance.FindEntityModelById(armyVo.cid);
            if (EntityTypeUtil.IsCurer(model))
            {
                attackerCurerCount += armyVo.amount;
            }
        }
        //加上援军的士兵数量
        foreach (var donatedArmy in DataCenter.Instance.Attacker.donatedArmies)
        {
            attackerArmyCount += donatedArmy.amount;

            var model = DataCenter.Instance.FindEntityModelById(donatedArmy.cid);
            if (EntityTypeUtil.IsCurer(model))
            {
                attackerCurerCount += donatedArmy.amount;
            }
        }

        //备份进攻方和防守方的数据,提交服务器时使用
        attackerData = ProtoBuf.Serializer.DeepClone(DataCenter.Instance.Attacker);
        defenderData = ProtoBuf.Serializer.DeepClone(DataCenter.Instance.Defender);
    }
Exemple #5
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");
    }
Exemple #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;
        }
    }
Exemple #7
0
    /// <summary>
    /// 创建模拟玩家数据
    /// </summary>
    /// <param name="userId"></param>
    private void CreateMockPlayerData(long userId = 1)
    {
        /// 1、构造建筑数据
        var buildings = new List <BuildingVO>();

        var mockProductionBuildingVO = new ProductionBuildingVO();
        //	    mockProductionBuildingVO.endTime = ServerTime.Instance.GetTimestamp(10);
        //        mockProductionBuildingVO.productionItems.Add(new ProductionItemVO(){cid=12601,count=10});

        var mockResoruceBuildingVO = new ResourceBuildingVO();

        mockResoruceBuildingVO.lastGatherTime = ServerTime.Instance.GetTimestamp(-60);
        buildings.Add(new BuildingVO()
        {
            buildingStatus = BuildingVO.BuildingStatus.On,
            cid            = 20101,//大本营
            sid            = 5,
            endTime        = ServerTime.Instance.GetTimestamp(10),
            x = 30,
            y = 30
        });
        buildings.Add(new BuildingVO()
        {
            buildingStatus = BuildingVO.BuildingStatus.On,
            cid            = 26601,//建造工人小屋
            sid            = 3,
            endTime        = ServerTime.Instance.GetTimestamp(10),
            x = 30,
            y = 40
        });
        buildings.Add(new BuildingVO()
        {
            buildingStatus = BuildingVO.BuildingStatus.On,
            cid            = 23801,//军营
            sid            = 4,
            endTime        = ServerTime.Instance.GetTimestamp(10),
            x = 40,
            y = 30
        });
        buildings.Add(new BuildingVO()
        {
            buildingStatus       = BuildingVO.BuildingStatus.On,
            cid                  = 21201,
            productionBuildingVO = mockProductionBuildingVO,
            sid                  = 1,
            endTime              = ServerTime.Instance.GetTimestamp(10),
            x = 40,
            y = 40
        });
        buildings.Add(new BuildingVO()
        {
            buildingStatus     = BuildingVO.BuildingStatus.On,
            cid                = 20201,
            resourceBuildingVO = mockResoruceBuildingVO,
            sid                = 2,
            endTime            = 0,
            x = 50,
            y = 40
        });
        buildings.Add(new BuildingVO()
        {
            buildingStatus     = BuildingVO.BuildingStatus.On,
            cid                = 20601,
            resourceBuildingVO = mockResoruceBuildingVO,
            sid                = 2,
            endTime            = 0,
            x = 50,
            y = 50
        });
        buildings.Add(new BuildingVO()
        {
            buildingStatus = BuildingVO.BuildingStatus.On,
            cid            = 23901,
            sid            = 7,
            endTime        = 0,
            x = 40,
            y = 50
        });
        var allTowers = new int[] { 21801, 21901, 22001, 22101, 22201, 22301, 22401, 22501 };

        //所有炮塔
        for (int i = 0; i < allTowers.Length; ++i)
        {
            buildings.Add(new BuildingVO()
            {
                buildingStatus = BuildingVO.BuildingStatus.On,
                cid            = allTowers[i],
                sid            = 8 + i,
                endTime        = 0,
                x = (i * 10) / 80,
                y = (i * 10) % 80
            });
        }

        var allTraps = new int[] { 21501, 21701, 26001, 26101, 26201 };

        for (int i = 0; i < allTraps.Length; i++)
        {
            buildings.Add(new BuildingVO()
            {
                buildingStatus = BuildingVO.BuildingStatus.On,
                trapBuildingVO = new TrapBuildingVO()
                {
                    broken = false
                },
                cid     = allTraps[i],
                sid     = 20 + i,
                endTime = 0,
                x       = 60 + (i * 10) / 80,
                y       = (i * 10) % 80
            });
        }

        /// 2、构造其他数据
        var campVO = new CampVO()
        {
            player = new PlayerVO()
        };

        //  player
        campVO.player.freeWorker = 4;
        campVO.player.maxWorker  = 4;
        campVO.player.baseId     = 20101;
        campVO.player.userId     = userId;
        campVO.player.raceType   = (int)RaceType.Predator;
        campVO.player.armyShop.AddRange(new[] {
            new ArmyExpVO()
            {
                cid = 22601, exp = 0
            },
            new ArmyExpVO()
            {
                cid = 22701, exp = 0
            },
            new ArmyExpVO()
            {
                cid = 22901, exp = 0
            },
            new ArmyExpVO()
            {
                cid = 23001, exp = 0
            },
            new ArmyExpVO()
            {
                cid = 23201, exp = 0
            },
            new ArmyExpVO()
            {
                cid = 22801, exp = 0
            },
            new ArmyExpVO()
            {
                cid = 23101, exp = 0
            },
            new ArmyExpVO()
            {
                cid = 23301, exp = 0
            }
        });
        campVO.player.skillShop.AddRange(new[] { 23401, 23601, 26301, 26401, 26501, 23501 });
        var myResoruce = new List <ResourceVO>();

        myResoruce.Add(new ResourceVO()
        {
            resourceType = ResourceType.Gold, resourceCount = 1000
        });
        myResoruce.Add(new ResourceVO()
        {
            resourceType = ResourceType.Oil, resourceCount = 1000
        });
        myResoruce.Add(new ResourceVO()
        {
            resourceType = ResourceType.Medal, resourceCount = 1000
        });
        myResoruce.Add(new ResourceVO()
        {
            resourceType = ResourceType.Diamond, resourceCount = 1000
        });
        campVO.player.resources.AddRange(myResoruce);
        //  building
        campVO.buildings.AddRange(buildings);
        //  armies&donatedArmies
        campVO.armies.Add(new ArmyVO()
        {
            amount = 20, cid = DataCenter.Instance.FindEntityModelByResourceName("PsoldierA01").baseId
        });
        campVO.armies.Add(new ArmyVO()
        {
            amount = 20, cid = DataCenter.Instance.FindEntityModelByResourceName("PsoldierB01").baseId
        });
        campVO.armies.Add(new ArmyVO()
        {
            amount = 20, cid = DataCenter.Instance.FindEntityModelByResourceName("PsoldierC01").baseId
        });
        campVO.armies.Add(new ArmyVO()
        {
            amount = 20, cid = DataCenter.Instance.FindEntityModelByResourceName("PsoldierD01").baseId
        });
        campVO.armies.Add(new ArmyVO()
        {
            amount = 20, cid = DataCenter.Instance.FindEntityModelByResourceName("PsoldierE01").baseId
        });
        campVO.armies.Add(new ArmyVO()
        {
            amount = 20, cid = DataCenter.Instance.FindEntityModelByResourceName("PsoldierF01").baseId
        });
        campVO.armies.Add(new ArmyVO()
        {
            amount = 20, cid = DataCenter.Instance.FindEntityModelByResourceName("PsoldierG01").baseId
        });
        campVO.armies.Add(new ArmyVO()
        {
            amount = 20, cid = DataCenter.Instance.FindEntityModelByResourceName("PsoldierH01").baseId
        });
        campVO.donatedArmies.AddRange(campVO.armies);

        campVO.skills.Add(new SkillVO()
        {
            amount = 10, cid = 26301
        });
        campVO.skills.Add(new SkillVO()
        {
            amount = 10, cid = 26401
        });
        campVO.skills.Add(new SkillVO()
        {
            amount = 10, cid = 26501
        });
        campVO.skills.Add(new SkillVO()
        {
            amount = 10, cid = 23401
        });
        campVO.skills.Add(new SkillVO()
        {
            amount = 10, cid = 23501
        });
        campVO.skills.Add(new SkillVO()
        {
            amount = 10, cid = 23601
        });

        /// 3、写入文件
        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 + "/palyer" + userId + ".bytes", FileMode.Create))
        {
            using (BinaryWriter writer = new BinaryWriter(fs))
            {
                writer.Write(bytes);
            }
        }
        Debug.Log("Saved");
    }
Exemple #8
0
    /// <summary>
    /// 得到大本营的Model
    /// </summary>
    /// <param name="owner"></param>
    /// <returns></returns>
    public EntityModel GetCenterBuildingModel(OwnerType owner = OwnerType.Defender)
    {
        CampVO camp = owner == OwnerType.Attacker ? Attacker : Defender;

        return(FindEntityModelById(camp.player.baseId));
    }
Exemple #9
0
    public void AddCrown(int crown, OwnerType owner = OwnerType.Defender)
    {
        CampVO camp = owner == OwnerType.Attacker ? Attacker : Defender;

        camp.player.crown += crown;
    }
Exemple #10
0
    public void SetCurCamp(CampVO campVO)
    {
        ModuleHomeLand module = (ModuleHomeLand)GameModule.GetModule(GameModule.MODULE_HOMELAND);

        module.campVO = campVO;
    }