Beispiel #1
0
    public BattlefieldData LoadBattlefieldData(string fileName, bool isFullPath = false)
    {
        string fullFile = BATTLEFIELD_SAVE_DIRECTORY + fileName + ".dat";

        if (isFullPath)
        {
            fullFile = fileName;
        }

        BattlefieldData data = Utility.LoadObjectFromFile <BattlefieldData> (fullFile);

        if (data != null)
        {
            data.spawns = new List <EnemySpawnPoint> ();
            for (int i = 0; i < data.spawnsX.Length; i++)
            {
                Vector3 start = new Vector3(data.spawnsX[i], data.spawnsY[i]);
                Vector3 end   = new Vector3(data.endsX[i], data.endsY[i]);

                EnemySpawnPoint spawn    = ScriptableObject.CreateInstance <EnemySpawnPoint>();
                EnemyEndPoint   endPoint = ScriptableObject.CreateInstance <EnemyEndPoint>();

                spawn.worldPosition    = start;
                endPoint.worldPosition = end;

                spawn.endPoint = endPoint;
                data.spawns.Add(spawn);
            }
            return(data);
        }
        return(null);
    }
Beispiel #2
0
    // Start is called before the first frame update
    private IEnumerator Init()
    {
        JobData.Load();
        SkillData.Load();
        EnemyData.Load();
        BattleTileData.Load();
        BattlefieldData.Load();
        BattleGroupData.Load();
        BattleStatusData.Load();
        ItemData.Load();
        EquipData.Load();
        ItemEffectData.Load();
        LanguageData.Load();
        DungeonData.Load();
        RoomData.Load();
        TreasureData.Load();
        ConversationData.Load();
        ShopData.Load();
        DungeonGroupData.Load();
        ExpData.Load();
        NewCookData.Load();

        yield return(new WaitForEndOfFrame());

        InitManager();

        MySceneManager.Instance.Load();

#if UNITY_EDITOR
        DebugCommand.Start();
#endif
    }
Beispiel #3
0
    public void SaveBattlefieldData(string fileName)
    {
        if (File.Exists(BATTLEFIELD_SAVE_DIRECTORY + fileName + ".dat"))
        {
            Debug.LogWarning("Tried to override file.");
            return;
        }

        BattlefieldData data = new BattlefieldData(fileName, "", battlefieldWidth, battlefieldHeight, isWalled, enemySpawnPoints);

        Utility.SaveObjectToFile(BATTLEFIELD_SAVE_DIRECTORY + fileName + ".dat", data);
    }
    public void GenerateFromTilemap(int id)
    {
        BattlefieldData.RootObject           battlefieldData = BattlefieldData.GetData(id);
        BattleTileData.RootObject            tileData;
        Dictionary <Vector2Int, BattleField> mapDic = new Dictionary <Vector2Int, BattleField>();
        TilemapToPositionList tilemapToPositionList = GameObject.Find("TilemapToPositionList").GetComponent <TilemapToPositionList>();
        List <Vector2Int>     positionList;

        //地板
        positionList = tilemapToPositionList.GetPositionList(0);
        tileData     = BattleTileData.GetData(battlefieldData.GroundID);
        for (int i = 0; i < positionList.Count; i++)
        {
            mapDic.Add(positionList[i], new BattleField(positionList[i], tileData));
        }

        //草
        positionList = tilemapToPositionList.GetPositionList(1);
        tileData     = BattleTileData.GetData(battlefieldData.GrassID);
        for (int i = 0; i < positionList.Count; i++)
        {
            //mapDic.Add(positionList[i], new BattleField(positionList[i], tileData));
            mapDic[positionList[i]].SetData(tileData);
        }

        //牆壁
        positionList = tilemapToPositionList.GetPositionList(2);
        tileData     = BattleTileData.GetData(battlefieldData.BlockID);
        for (int i = 0; i < positionList.Count; i++)
        {
            //mapDic.Add(positionList[i], new BattleField(positionList[i], tileData));
            mapDic[positionList[i]].SetData(tileData);
        }

        //敵人的位置
        List <Vector2Int> enemyPositionList = new List <Vector2Int>();

        enemyPositionList.Add(new Vector2Int(0, 2));

        BattleFieldManager.Instance.Init(Vector2Int.zero, enemyPositionList, mapDic);
    }
    public void Generate(int id, int enemyAmount)
    {
        Vector2Int        center;
        List <Vector2Int> reservedLits = new List <Vector2Int>(); //地圖中間的九宮格是保留區,不生成特殊地形
        Dictionary <Vector2Int, BattleField> mapDic = new Dictionary <Vector2Int, BattleField>();

        BattlefieldData.RootObject battlefieldData = BattlefieldData.GetData(id);
        int width  = Random.Range(battlefieldData.MinWidth, battlefieldData.MaxWidth + 1);
        int height = Random.Range(battlefieldData.MinHeight, battlefieldData.MaxHeight + 1);

        center = new Vector2Int(width / 2, height / 2);

        reservedLits.Add(center);
        reservedLits.Add(center + Vector2Int.left + Vector2Int.up);
        reservedLits.Add(center + Vector2Int.up);
        reservedLits.Add(center + Vector2Int.right + Vector2Int.up);
        reservedLits.Add(center + Vector2Int.left);
        reservedLits.Add(center + Vector2Int.right);
        reservedLits.Add(center + Vector2Int.left + Vector2Int.down);
        reservedLits.Add(center + Vector2Int.down);
        reservedLits.Add(center + Vector2Int.right + Vector2Int.down);

        Vector2Int pos = new Vector2Int();

        BattleTileData.RootObject tileData;

        //地板
        tileData = BattleTileData.GetData(battlefieldData.GroundID);
        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                pos.x = i;
                pos.y = j;
                mapDic.Add(pos, new BattleField(pos, tileData));
                TilePainter.Instance.Painting(tileData.TileName, 0, pos);
            }
        }

        //敵人的位置
        List <Vector2Int> tempPositionList  = new List <Vector2Int>(mapDic.Keys);
        List <Vector2Int> enemyPositionList = new List <Vector2Int>();

        for (int i = 0; i < reservedLits.Count; i++)
        {
            tempPositionList.Remove(reservedLits[i]);
        }

        Vector2Int firstPos = new Vector2Int();

        firstPos = tempPositionList[Random.Range(0, tempPositionList.Count)];
        enemyPositionList.Add(firstPos); //第一個敵人的位置
        Debug.Log("1:" + firstPos);
        tempPositionList.Remove(firstPos);
        for (int i = 1; i < enemyAmount; i++) //其他敵人的位置與第一個敵人的位置相近
        {
            while (tempPositionList.Count > 0)
            {
                pos = tempPositionList[Random.Range(0, tempPositionList.Count)];
                tempPositionList.Remove(pos);
                if (Utility.GetDistance(pos, firstPos) <= enemyAmount)
                {
                    enemyPositionList.Add(pos);
                    Debug.Log(i + ":" + pos);
                    break;
                }
            }
        }

        //牆壁
        tileData = BattleTileData.GetData(battlefieldData.BlockID);

        int blockCount = Random.Range(battlefieldData.MinBlockCount, battlefieldData.MaxBlockCount);

        for (int i = 0; i < blockCount; i++)
        {
            pos = tempPositionList[Random.Range(0, tempPositionList.Count)];
            mapDic[pos].SetData(tileData);
            TilePainter.Instance.Painting(tileData.TileName, 0, pos);
            tempPositionList.Remove(pos);
        }

        //草
        tileData = BattleTileData.GetData(battlefieldData.GrassID);
        int grassCount = Random.Range(battlefieldData.MinGrassCount, battlefieldData.MaxGrassCount);

        for (int i = 0; i < grassCount; i++)
        {
            pos = tempPositionList[Random.Range(0, tempPositionList.Count)];
            mapDic[pos].SetData(tileData);
            TilePainter.Instance.Painting(tileData.TileName, 0, pos);
            tempPositionList.Remove(pos);
        }

        //Camera Wall
        GameObject wall;

        //up
        wall = ResourceManager.Instance.Spawn("CameraWall", ResourceManager.Type.Other);
        wall.transform.localScale = new Vector3(width + 2, 1, 1);
        wall.transform.position   = new Vector3(width / 2f - 0.5f, height + 1, 0);

        //down
        wall = ResourceManager.Instance.Spawn("CameraWall", ResourceManager.Type.Other);
        wall.transform.localScale = new Vector3(width + 2, 1, 1);
        wall.transform.position   = new Vector3(width / 2f - 0.5f, 0, 0);

        //left
        wall = ResourceManager.Instance.Spawn("CameraWall", ResourceManager.Type.Other);
        wall.transform.localScale = new Vector3(1, height + 2, 1);
        wall.transform.position   = new Vector3(-1, height / 2f + 0.5f, 0);

        //right
        wall = ResourceManager.Instance.Spawn("CameraWall", ResourceManager.Type.Other);
        wall.transform.localScale = new Vector3(1, height + 2, 1);
        wall.transform.position   = new Vector3(width, height / 2f + 0.5f, 0);


        BattleFieldManager.Instance.Init(center, enemyPositionList, mapDic);
    }
Beispiel #6
0
        /**
         * Consumeable item buffs will be routed here.
         * This includes HP/MP items along with temp stat increase items
         */
        public void UsePotion(int nItemID, short nPOS)
        {
            if (Parent.Stats.nHP <= 0)
            {
                return;
            }

            if (InventoryManipulator.GetItem(Parent, InventoryType.Consume, nPOS)?.Template is ConsumeItemTemplate template)
            {
                if (Parent.Field is CField_Battlefield bf)                 // if not remove item anyway cuz they shouldnt have it
                {
                    // TODO effects => Effect/BasicEff/ItemSkill/Success

                    if (template.BFSkill < 0)
                    {
                        if (BattlefieldData.SheepConsumable(nItemID) || BattlefieldData.WolfConsumable(nItemID))
                        {
                            var newBuff = new BuffConsume(nItemID);
                            newBuff.GenerateConsumeable(Parent);
                        }
                    }
                    else
                    {
                        switch (template.BFSkill)                         // we hardcodin' bois
                        {
                        case 0:
                            Parent.SendMessage("You cry at the Wolf, and it slows down as if it's in shock.");
                            bf.Users.ForEach(u =>
                            {
                                if (bf.GetPlayerTeam(u.dwId) == BattlefieldData.BattlefieldTeams.Wolves)
                                {
                                    u.Buffs.OnStatChangeByMobSkill(MasterManager.MobSkillTemplates[126][9], 0, 0);
                                }
                            });
                            break;

                        case 1:
                            Parent.SendMessage("You attack the Wolf. He should be momentarily stunned.");
                            bf.Users.ForEach(u =>
                            {
                                if (bf.GetPlayerTeam(u.dwId) == BattlefieldData.BattlefieldTeams.Wolves)
                                {
                                    u.Buffs.OnStatChangeByMobSkill(MasterManager.MobSkillTemplates[123][14], 0, 0);
                                }
                            });
                            break;

                        case 2:
                            Parent.Field.BroadcastNotice("The Sheep are in a state of confusion.");
                            bf.Users.ForEach(u =>
                            {
                                if (bf.GetPlayerTeam(u.dwId) != BattlefieldData.BattlefieldTeams.Wolves)
                                {
                                    u.Buffs.OnStatChangeByMobSkill(MasterManager.MobSkillTemplates[132][4], 0, 0);
                                }
                            });
                            break;

                        case 3:
                            Parent.Field.BroadcastNotice("The Wolves have slowed down.");
                            bf.Users.ForEach(u =>
                            {
                                if (bf.GetPlayerTeam(u.dwId) == BattlefieldData.BattlefieldTeams.Wolves)
                                {
                                    u.Buffs.OnStatChangeByMobSkill(MasterManager.MobSkillTemplates[126][10], 0, 0);
                                }
                            });
                            break;

                        case 4:
                            Parent.Field.BroadcastNotice("The Sheep are momentarily stunned.");
                            bf.Users.ForEach(u =>
                            {
                                if (bf.GetPlayerTeam(u.dwId) != BattlefieldData.BattlefieldTeams.Wolves)
                                {
                                    u.Buffs.OnStatChangeByMobSkill(MasterManager.MobSkillTemplates[123][15], 0, 0);
                                }
                            });
                            break;

                        case 5:
                            Parent.Field.BroadcastNotice("The Sheep have momentarily weakened.");
                            bf.Users.ForEach(u =>
                            {
                                if (bf.GetPlayerTeam(u.dwId) != BattlefieldData.BattlefieldTeams.Wolves)
                                {
                                    u.Buffs.OnStatChangeByMobSkill(MasterManager.MobSkillTemplates[122][12], 0, 0);
                                }
                            });
                            break;
                        }
                    }
                }
                else
                {
                    if (Parent.Field.Template.HasStatChangeItemLimit())
                    {
                        Parent.SendMessage("Not allowed in this map.");
                        return;
                    }

                    var newBuff = new BuffConsume(nItemID);
                    newBuff.GenerateConsumeable(Parent);
                    // buff gets added in the generator if it has bufftime
                }
            }

            InventoryManipulator.RemoveFrom(Parent, InventoryType.Consume, nPOS);             // remove regardless
        }