Пример #1
0
    /// <summary>
    /// Spawns a village character behind the scenes which can later be recruited by the player.
    /// </summary>
    /// <param name="pos"></param>
    /// <returns></returns>
    public TacticsMove SpawnVillageCharacter(InteractPosition pos)
    {
        SpawnData reinforcement = new SpawnData()
        {
            x         = pos.x,
            y         = pos.y,
            level     = pos.ally.level,
            charData  = pos.ally.charData,
            inventory = pos.ally.inventory
        };

        return(SpawnPlayerCharacter(reinforcement, false, false, false));
    }
Пример #2
0
    private void DrawInteractStuff()
    {
        MapEntry mapValues = (MapEntry)entryValues;

        GUILayout.Space(5);
        for (int i = 0; i < mapValues.interactions.Count; i++)
        {
            InteractPosition pos = mapValues.interactions[i];
            GUILayout.BeginHorizontal();
            EditorGUIUtility.labelWidth = 70;
            GUILayout.Label("Position");
            pos.x = EditorGUILayout.IntField("X", pos.x);
            pos.y = EditorGUILayout.IntField("Y", pos.y);
            if (GUILayout.Button("X", GUILayout.Width(50)))
            {
                GUI.FocusControl(null);
                mapValues.interactions.RemoveAt(i);
                i--;
                continue;
            }
            EditorGUIUtility.labelWidth = 120;
            GUILayout.EndHorizontal();

            pos.interactType = (InteractType)EditorGUILayout.EnumPopup("Type", pos.interactType);

            switch (pos.interactType)
            {
            case InteractType.BLOCK:
                pos.health = EditorGUILayout.IntField("Health", pos.health);
                break;

            case InteractType.VILLAGE:
                pos.dialogue = (DialogueEntry)EditorGUILayout.ObjectField("Dialogue", pos.dialogue, typeof(DialogueEntry), false);
                GUILayout.BeginHorizontal();
                pos.gift.money = EditorGUILayout.IntField("Money", pos.gift.money);
                pos.gift.scrap = EditorGUILayout.IntField("Scrap", pos.gift.scrap);
                GUILayout.EndHorizontal();
                if (pos.gift.items.Count < 1)
                {
                    pos.gift.items.Add(null);
                }
                pos.gift.items[0] = (ItemEntry)EditorGUILayout.ObjectField("Item", pos.gift.items[0], typeof(ItemEntry), false);
                pos.ally.charData = (CharEntry)EditorGUILayout.ObjectField("New ally", pos.ally.charData, typeof(CharEntry), false);
                if (pos.ally.charData != null)
                {
                    pos.ally.level = EditorGUILayout.IntField("Level", pos.ally.level);

                    EditorGUIUtility.labelWidth = 70;
                    for (int j = 0; j < pos.ally.inventory.Count; j++)
                    {
                        GUILayout.BeginHorizontal();
                        pos.ally.inventory[j].item = (ItemEntry)EditorGUILayout.ObjectField("Item", pos.ally.inventory[j].item, typeof(ItemEntry), false);
                        if (GUILayout.Button("X", GUILayout.Width(50)))
                        {
                            GUI.FocusControl(null);
                            pos.ally.inventory.RemoveAt(j);
                            i--;
                        }
                        GUILayout.EndHorizontal();
                    }
                    EditorGUIUtility.labelWidth = 120;
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(120);
                    if (GUILayout.Button("Add Item"))
                    {
                        pos.ally.inventory.Add(new WeaponTuple());
                    }
                    GUILayout.EndHorizontal();
                }
                break;

            case InteractType.DATABASE:
                GUILayout.BeginHorizontal();
                EditorGUIUtility.labelWidth = 55;
                pos.gift.money = EditorGUILayout.IntField("Money", pos.gift.money, GUILayout.Width(120));
                pos.gift.scrap = EditorGUILayout.IntField("Scrap", pos.gift.scrap, GUILayout.Width(120));
                if (pos.gift.items.Count < 1)
                {
                    pos.gift.items.Add(null);
                }
                pos.gift.items[0] = (ItemEntry)EditorGUILayout.ObjectField("Item", pos.gift.items[0], typeof(ItemEntry), false);
                GUILayout.EndHorizontal();
                EditorGUIUtility.labelWidth = 120;
                break;
            }

            LibraryEditorWindow.HorizontalLine(Color.black);
        }
        if (GUILayout.Button("+"))
        {
            mapValues.interactions.Add(new InteractPosition());
        }
    }
Пример #3
0
    /// <summary>
    /// Takes a texture representing the map and generates tiles from the pixels' color values.
    /// </summary>
    /// <param name="texMap"></param>
    public void GenerateMap(Texture2D texMap)
    {
        MapEntry map = (MapEntry)currentMap.value;

        Color32[]      colorData = texMap.GetPixels32();
        int            pos       = 0;
        List <MapTile> mappus    = new List <MapTile>();

        battleMap.breakables.Clear();

        for (int j = 0; j < _sizeY; j++)
        {
            for (int i = 0; i < _sizeX; i++)
            {
                InteractPosition interPos = GetInteractable(map, i, j);
                Transform        tile     = (interPos != null && interPos.interactType == InteractType.BLOCK) ? Instantiate(blockTilePrefab) : Instantiate(tilePrefab);
                tile.position = new Vector3(i, j, 0);
                tile.SetParent(battleMap.tileParent);

                MapTile tempTile = tile.GetComponent <MapTile>();
                tempTile.battlemap = battleMap;
                tempTile.posx      = i;
                tempTile.posy      = j;
                if (interPos == null)
                {
                    tempTile.SetTerrain(GetTerrainFromPixel(colorData[pos]));
                }
                else if (interPos.interactType == InteractType.BLOCK)
                {
                    tempTile.interactType = InteractType.BLOCK;
                    tempTile.SetTerrain(tileBreakable);
                    tempTile.alternativeTerrain = GetTerrainFromPixel(colorData[pos]);
                    battleMap.breakables.Add(tempTile);

                    BlockMove block = tempTile.GetComponent <BlockMove>();
                    block.currentTile   = tempTile;
                    block.stats.hp      = interPos.health;
                    block.currentHealth = interPos.health;
                }
                else if (interPos.interactType == InteractType.VILLAGE)
                {
                    tempTile.interactType       = InteractType.VILLAGE;
                    tempTile.alternativeTerrain = GetTerrainFromPixel(colorData[pos]);
                    tempTile.dialogue           = interPos.dialogue;
                    tempTile.gift = interPos.gift;
                    if (interPos.ally.charData != null)
                    {
                        tempTile.ally = mapSpawner.SpawnVillageCharacter(interPos);
                        Debug.Log("Spawned ally:  " + tempTile.ally.name);
                    }
                    TerrainTile terrain = (interPos.gift == null && interPos.ally == null) ? tileHouse : tileHouseReward;
                    tempTile.SetTerrain(terrain);
                }
                else if (interPos.interactType == InteractType.CAPTURE)
                {
                    tempTile.SetTerrain(GetTerrainFromPixel(colorData[pos]));
                    tempTile.interactType = InteractType.CAPTURE;
                }
                else if (interPos.interactType == InteractType.ESCAPE)
                {
                    tempTile.SetTerrain(GetTerrainFromPixel(colorData[pos]));
                    tempTile.interactType = InteractType.ESCAPE;
                }
                else if (interPos.interactType == InteractType.DATABASE)
                {
                    tempTile.SetTerrain(tileChest);
                    tempTile.alternativeTerrain = tileChest.substitueTile;
                    tempTile.interactType       = InteractType.DATABASE;
                    tempTile.gift = interPos.gift;
                }
                else if (interPos.interactType == InteractType.DOOR)
                {
                    tempTile.SetTerrain(tileDoor);
                    tempTile.alternativeTerrain = tileDoor.substitueTile;
                    tempTile.interactType       = InteractType.DOOR;
                    tempTile.gift = interPos.gift;
                }
                else
                {
                    Debug.LogError("Unimplemented interact type   " + interPos.interactType);
                }
                mappus.Add(tempTile);

                pos++;
            }
        }

        battleMap.tiles = mappus.ToArray();
        Debug.Log("Data read and map created");
    }