예제 #1
0
    // Start is called before the first frame update
    void Start()
    {
        actualMovementPoint = movementPoint;
        Tilemap characterLayer = GameObject.FindGameObjectWithTag("CharacterLayer").GetComponent <Tilemap>();


        Vector3Int pos = characterLayer.WorldToCell(transform.position);

        pos.z = 0;
        Vector3 newPos = characterLayer.GetCellCenterWorld(pos);

        newPos.z           = -1.2f;
        transform.position = newPos;
        characterLayer.SetTile(pos, characterTile);
        TileBase      t   = characterLayer.GetTile(pos);
        CharacterTile tmp = Instantiate(t) as CharacterTile;

        tmp.character = this.gameObject;
        characterLayer.SetTile(pos, tmp);

        attackUI = Instantiate(attackSprite, this.transform);
        attackUI.transform.position = new Vector3(attackUI.transform.position.x + 0.2f, attackUI.transform.position.y + 0.2f, attackUI.transform.position.z);

        movementUI = Instantiate(movementSprite, this.transform);
        movementUI.transform.position = new Vector3(movementUI.transform.position.x + 0.35f, movementUI.transform.position.y + 0.2f, movementUI.transform.position.z);
        movementPointText             = new GameObject("movementPointText");
        movementPointText.transform.SetParent(GameObject.FindGameObjectWithTag("UI Infos").transform);
        movementPointText.AddComponent <Text>();
        movementPointText.GetComponent <Text>().font      = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
        movementPointText.GetComponent <Text>().fontSize  = 14;
        movementPointText.GetComponent <Text>().fontStyle = FontStyle.Bold;
        movementPointText.GetComponent <Text>().color     = Color.white;

        healthUI = Instantiate(healthSprite, this.transform);
        healthUI.transform.position = new Vector3(healthUI.transform.position.x + 0.55f, healthUI.transform.position.y + 0.2f, healthUI.transform.position.z);
        healthPointText             = new GameObject("healthPointText");
        healthPointText.transform.SetParent(GameObject.FindGameObjectWithTag("UI Infos").transform);
        healthPointText.AddComponent <Text>();
        healthPointText.GetComponent <Text>().font      = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
        healthPointText.GetComponent <Text>().fontSize  = 14;
        healthPointText.GetComponent <Text>().fontStyle = FontStyle.Bold;
        healthPointText.GetComponent <Text>().color     = Color.white;
    }
예제 #2
0
 public void importArmy(Tilemap characterLayer)
 {
     army.Clear();
     foreach (Vector3Int position in characterLayer.cellBounds.allPositionsWithin)
     {
         TileBase t = characterLayer.GetTile(position);
         if (!Equals(t, null))
         {
             if (t is CharacterTile)
             {
                 CharacterTile gt = Instantiate(t) as CharacterTile;
                 if (gt.character.GetComponent <Character>() != null)
                 {
                     GameObject chara = gt.character;
                     if (chara.GetComponent <Character>().ally == true)
                     {
                         army.Add(chara);
                     }
                 }
             }
         }
     }
 }
예제 #3
0
 public void endTurn(bool ally)
 {
     foreach (Vector3Int position in characterLayer.cellBounds.allPositionsWithin)
     {
         TileBase t = characterLayer.GetTile(position);
         if (!Equals(t, null))
         {
             if (t is CharacterTile)
             {
                 CharacterTile gt = Instantiate(t) as CharacterTile;
                 if (gt.character.GetComponent <Character>() != null)
                 {
                     GameObject chara = gt.character;
                     if (chara.GetComponent <Character>().ally == ally)
                     {
                         chara.GetComponent <Character>().actualMovementPoint = chara.GetComponent <Character>().movementPoint;
                         chara.GetComponent <Character>().canAttacked         = true;
                     }
                 }
             }
         }
     }
 }
예제 #4
0
        private void WriteMetaSprites(StreamWriter outputFile, CharacterModel model, string name)
        {
            ProjectModel projectModel = ModelManager.Get <ProjectModel>();

            int nesFPS = projectModel.Header.FrameTiming == FrameTiming.NTSC ? NTSC : PAL;

            List <string> animationIndices = new List <string>();

            foreach (CharacterAnimation animation in model.Animations)
            {
                if (string.IsNullOrEmpty(animation.ID))
                {
                    continue;
                }

                int           frameIndex = 0;
                List <string> frameNames = new List <string>();

                for (int i = 0; i < animation.Frames.Length; ++i)
                {
                    if (animation.Frames[i].Tiles == null)
                    {
                        continue;
                    }

                    string frameName = $"{name}_{animation.Name}_data_{frameIndex++}";

                    bool foundFrame = false;

                    for (int j = 0; j < animation.Frames[i].Tiles.Length; ++j)
                    {
                        CharacterTile charTile = animation.Frames[i].Tiles[j];

                        if (string.IsNullOrEmpty(charTile.BankID) || string.IsNullOrEmpty(charTile.BankTileID))
                        {
                            continue;
                        }

                        if (foundFrame == false)
                        {
                            frameNames.Add(frameName);

                            outputFile.WriteLine($"{frameName}:");
                            outputFile.WriteLine(";          vert   tile   attr   horiz");

                            foundFrame = true;
                        }

                        byte horiz = (byte)charTile.Point.X;
                        byte vert  = (byte)charTile.Point.Y;

                        BankModel bank = ProjectFiles.GetModel <BankModel>(charTile.BankID);
                        byte      tile = (byte)bank.GetTileIndex(charTile.BankTileID);

                        int paletteIndex = charTile.PaletteIndex;

                        byte attrs = (byte)paletteIndex;
                        attrs |= charTile.BackBackground ? (byte)32 : (byte)0;
                        attrs |= charTile.FlipX ? (byte)64 : (byte)0;
                        attrs |= charTile.FlipY ? (byte)128 : (byte)0;

                        outputFile.WriteLine($"    .byte   ${vert:X2},   ${tile:X2},   ${attrs:X2},   ${horiz:X2}");
                    }

                    if (foundFrame)
                    {
                        // Add the termination byte
                        outputFile.WriteLine("    .byte   $FF");
                        outputFile.WriteLine("");
                    }
                }

                outputFile.WriteLine($"{name}_{animation.Name}_data:");

                animationIndices.Add($"{animation.Name}");

                int frameDuration = (int)(nesFPS * animation.Speed);

                int colBoxAx = animation.CollisionInfo == null ? 0 : animation.CollisionInfo.OffsetX;
                int colBoxAy = animation.CollisionInfo == null ? 0 : animation.CollisionInfo.OffsetY;
                int colBoxBx = animation.CollisionInfo == null ? 0 : animation.CollisionInfo.OffsetX + animation.CollisionInfo.Width;
                int colBoxCy = animation.CollisionInfo == null ? 0 : animation.CollisionInfo.OffsetY + animation.CollisionInfo.Height;

                outputFile.WriteLine($"    ; number of frames");
                outputFile.WriteLine($"    .byte ${frameNames.Count:X2} ; decimal {frameNames.Count}");
                outputFile.WriteLine($"    ; frame duration");
                outputFile.WriteLine($"    .byte ${frameDuration:X2} ; decimal {frameDuration}");
                outputFile.WriteLine($"    ; collision");
                outputFile.WriteLine($"    ; a____b");
                outputFile.WriteLine($"    ; |    |");
                outputFile.WriteLine($"    ; |____|");
                outputFile.WriteLine($"    ; c    d");
                outputFile.WriteLine($"    ;        a       b     c");
                outputFile.WriteLine($"    ;      x    y    x     y");
                outputFile.Write($"    .byte ");
                outputFile.Write($"${colBoxAx:X2}, ");
                outputFile.Write($"${colBoxAy:X2}, ");
                outputFile.Write($"${colBoxBx:X2}, ");
                outputFile.Write($"${colBoxCy:X2}");
                outputFile.Write(Environment.NewLine);

                foreach (string frameName in frameNames)
                {
                    outputFile.WriteLine($"    .addr {frameName}");
                }

                outputFile.WriteLine("");
            }

            if (animationIndices.Count > 0)
            {
                outputFile.WriteLine("; aninmation indices");

                for (int i = 0; i < animationIndices.Count; ++i)
                {
                    string index     = animationIndices[i].ToUpper();
                    string nameUpper = name.ToUpper();

                    outputFile.WriteLine($"ANIM_{nameUpper}_{index} = ${i:X2}");
                }

                outputFile.WriteLine("");

                outputFile.WriteLine($"{name}_anim_num_map:");

                for (int i = 0; i < animationIndices.Count; ++i)
                {
                    string index = animationIndices[i];

                    outputFile.WriteLine($"    .addr {name}_{index}_data");
                }
            }
        }
예제 #5
0
        static void LoadPlayerSaveFile()
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(@"./Content/Save/PlayerSave.xml");
            XmlNode     root     = xmlDoc.SelectSingleNode("CV");
            XmlNodeList rootList = root.ChildNodes;

            foreach (XmlNode rootNode in rootList)
            {
                switch (rootNode.Name)
                {
                case "Global":
                    XmlNodeList rootGlobalList = rootNode.ChildNodes;
                    foreach (XmlNode rootGlobalNode in rootGlobalList)
                    {
                        switch (rootGlobalNode.Name)
                        {
                        case "Time":
                            GlobalController.Time = float.Parse(rootGlobalNode.InnerText);
                            break;

                        case "Year":
                            GlobalController.Year = int.Parse(rootGlobalNode.InnerText);
                            break;

                        case "Season":
                            GlobalController.Season = int.Parse(rootGlobalNode.InnerText);
                            break;

                        case "Date":
                            GlobalController.Date = int.Parse(rootGlobalNode.InnerText);
                            break;

                        case "WeekDay":
                            GlobalController.WeekDay = int.Parse(rootGlobalNode.InnerText);
                            break;

                        case "Weather":
                            GlobalController.Weather = rootGlobalNode.InnerText;
                            break;

                        case "IsShipment":
                            GlobalController.isShipment = bool.Parse(rootGlobalNode.InnerText);
                            break;

                        default:
                            break;
                        }
                    }
                    break;

                case "Player":
                    XmlNodeList rootPlayerList = rootNode.ChildNodes;
                    foreach (XmlNode rootPlayerNode in rootPlayerList)
                    {
                        switch (rootPlayerNode.Name)
                        {
                        case "Map":
                            GlobalController.CStatus = new GlobalController.Cs
                            {
                                cName = rootPlayerNode.InnerText,
                                func  = 0
                            };
                            break;

                        case "Position":
                            GlobalController.PlayerWithoutInit.Position = new Vector2(float.Parse(rootPlayerNode.InnerText.Split('|')[0]), float.Parse(rootPlayerNode.InnerText.Split('|')[1]));
                            break;

                        case "Name":
                            GlobalController.PlayerWithoutInit.Name = rootPlayerNode.InnerText;
                            break;

                        case "Character":
                            XmlNodeList     elementList = rootPlayerNode.ChildNodes;
                            CharacterTile[] cTile       = new CharacterTile[8];
                            for (int i = 0; i < 8; i++)
                            {
                                string   context = elementList[i].InnerText;
                                string[] inner   = context.Split('|');
                                cTile[i] = new CharacterTile(int.Parse(inner[0]), int.Parse(inner[1]), inner[2], inner[4], inner[6], inner[8], inner[10], inner[12], inner[14], inner[16], inner[18], inner[20], inner[22], inner[24], int.Parse(inner[3].Split(',')[0]), int.Parse(inner[3].Split(',')[1]), int.Parse(inner[5].Split(',')[0]), int.Parse(inner[5].Split(',')[1]), int.Parse(inner[7].Split(',')[0]), int.Parse(inner[7].Split(',')[1]), int.Parse(inner[9].Split(',')[0]), int.Parse(inner[9].Split(',')[1]), int.Parse(inner[11].Split(',')[0]), int.Parse(inner[11].Split(',')[1]), int.Parse(inner[13].Split(',')[0]), int.Parse(inner[13].Split(',')[1]), int.Parse(inner[15].Split(',')[0]), int.Parse(inner[15].Split(',')[1]), int.Parse(inner[17].Split(',')[0]), int.Parse(inner[17].Split(',')[1]), int.Parse(inner[19].Split(',')[0]), int.Parse(inner[19].Split(',')[1]), int.Parse(inner[21].Split(',')[0]), int.Parse(inner[21].Split(',')[1]), int.Parse(inner[23].Split(',')[0]), int.Parse(inner[23].Split(',')[1]), int.Parse(inner[25].Split(',')[0]), int.Parse(inner[25].Split(',')[1]));
                            }
                            GlobalController.PlayerWithoutInit.CTile = cTile;
                            break;

                        case "Speed":
                            GlobalController.PlayerWithoutInit.Speed = float.Parse(rootPlayerNode.InnerText);
                            break;

                        case "Gender":
                            GlobalController.PlayerWithoutInit.Gender = bool.Parse(rootPlayerNode.InnerText);
                            break;

                        case "HasLight":
                            GlobalController.PlayerWithoutInit.HasLight = bool.Parse(rootPlayerNode.InnerText);
                            break;

                        case "HpUpper":
                            GlobalController.PlayerWithoutInit.HpUpper = float.Parse(rootPlayerNode.InnerText);
                            break;

                        case "Hp":
                            GlobalController.PlayerWithoutInit.Hp = float.Parse(rootPlayerNode.InnerText);
                            break;

                        case "EnergyUpper":
                            GlobalController.PlayerWithoutInit.EnergyUpper = float.Parse(rootPlayerNode.InnerText);
                            break;

                        case "Energy":
                            GlobalController.PlayerWithoutInit.Energy = float.Parse(rootPlayerNode.InnerText);
                            break;

                        case "Habitus":
                            GlobalController.PlayerWithoutInit.Habitus = float.Parse(rootPlayerNode.InnerText);
                            break;

                        case "Hunger":
                            GlobalController.PlayerWithoutInit.Hunger = float.Parse(rootPlayerNode.InnerText);
                            break;

                        case "Gold":
                            GlobalController.PlayerWithoutInit.Gold = int.Parse(rootPlayerNode.InnerText);
                            break;

                        case "IsDisease":
                            GlobalController.PlayerWithoutInit.IsDisease = bool.Parse(rootPlayerNode.InnerText);
                            break;

                        case "Inventory":
                            XmlNodeList inventoryList = rootPlayerNode.ChildNodes;
                            for (int i = 0; i < inventoryList.Count; i++)
                            {
                                if (i == 0)
                                {
                                    GlobalController.InventoryCount = int.Parse(inventoryList[i].InnerText);
                                    for (int j = 0; j < GlobalController.InventoryCount; j++)
                                    {
                                        GlobalController.InventoryList.Add(new Inventory(null, true, j + 1, 0));
                                    }
                                }
                                else
                                {
                                    GlobalController.InventoryList[i - 1].AddItem(Item.ItemCreateFactory(inventoryList[i].InnerText.Substring(0, 6)), int.Parse(inventoryList[i].InnerText.Substring(7, inventoryList[i].InnerText.Length - 7)));
                                }
                            }
                            break;

                        case "RapidRoom":
                            XmlNodeList RapidRoomList = rootPlayerNode.ChildNodes;
                            for (int i = 0; i < RapidRoomList.Count; i++)
                            {
                                if (i == 0)
                                {
                                    GlobalController.RapidRoomCount = int.Parse(RapidRoomList[i].InnerText);
                                    for (int j = 0; j < GlobalController.RapidRoomCount; j++)
                                    {
                                        GlobalController.RapidRoomList.Add(new Inventory(null, true, j + 1, 0));
                                    }
                                }
                                else
                                {
                                    GlobalController.RapidRoomList[i - 1].AddItem(Item.ItemCreateFactory(RapidRoomList[i].InnerText.Substring(0, 6)), int.Parse(RapidRoomList[i].InnerText.Substring(7, RapidRoomList[i].InnerText.Length - 7)));
                                }
                            }
                            break;

                        case "SelectingRapidRoom":
                            XmlNodeList SelectingRapidRoom = rootPlayerNode.ChildNodes;
                            GlobalController.SelectingRapidRoomItem = new Inventory(null, true, 0, 0);
                            if (SelectingRapidRoom.Count > 0)
                            {
                                GlobalController.SelectingRapidRoomItem.AddItem(Item.ItemCreateFactory(SelectingRapidRoom[0].InnerText.Substring(0, 6)), int.Parse(SelectingRapidRoom[0].InnerText.Substring(7, SelectingRapidRoom[0].InnerText.Length - 7)));
                            }
                            break;

                        default:
                            break;
                        }
                    }
                    break;

                case "Shop":
                    XmlNodeList rootShopList = rootNode.ChildNodes;

                    foreach (XmlNode node in rootShopList)
                    {
                        Shops shop = new Shops(ResourceController.UI_ordinary, ResourceController.UI_logos, Map.Null, node.Name);
                        foreach (XmlNode item in node)
                        {
                            string[] inner = item.InnerText.Split('|');
                            shop.AddGoods(new Goods(Item.ItemCreateFactory(inner[0]), int.Parse(inner[1]), float.Parse(inner[2])));
                        }
                        GlobalController.Global_Shops.Add(shop);
                    }
                    break;

                case "PlayerScene":
                    XmlNodeList rootPlayerSceneList = rootNode.ChildNodes;
                    foreach (XmlNode rootPlayerSceneNode in rootPlayerSceneList)
                    {
                        switch (rootPlayerSceneNode.Name)
                        {
                        case "Chest":
                            string[] contextChest = rootPlayerSceneNode.InnerText.Split('|');
                            Chest    chest        = new Chest(new Map(contextChest[0]), new Vector2(int.Parse(contextChest[1]), int.Parse(contextChest[2])), ResourceController.Scenes_chest, int.Parse(contextChest[3]));
                            for (int i = 4; i < contextChest.Length; i++)
                            {
                                string[] contextChestItem = contextChest[i].Split('^');
                                chest.Inventries[int.Parse(contextChestItem[2])].AddItem(Item.ItemCreateFactory(contextChestItem[0]), int.Parse(contextChestItem[1]));
                            }
                            GlobalController.PlayerSceneList.Add(chest);
                            break;

                        case "Soil":
                            string[] contextSoil = rootPlayerSceneNode.InnerText.Split('|');
                            if (contextSoil[4] == "True")
                            {
                                Soil soil = new Soil(ResourceController.Scenes_soil, new Map(contextSoil[0]), new Vector2(int.Parse(contextSoil[1]), int.Parse(contextSoil[2])), float.Parse(contextSoil[3]), Item.ItemCreateFactory(contextSoil[5]) as Seeds, true);
                                soil.Seed.LoadingSeeds(float.Parse(contextSoil[6]), bool.Parse(contextSoil[7]), bool.Parse(contextSoil[8]), bool.Parse(contextSoil[9]), float.Parse(contextSoil[10]), float.Parse(contextSoil[11]), float.Parse(contextSoil[12]), float.Parse(contextSoil[13]), float.Parse(contextSoil[14]), float.Parse(contextSoil[15]), float.Parse(contextSoil[16]), float.Parse(contextSoil[17]));
                                GlobalController.SoilList.Add(soil);
                            }
                            else
                            {
                                Soil soil = new Soil(ResourceController.Scenes_soil, new Map(contextSoil[0]), new Vector2(int.Parse(contextSoil[1]), int.Parse(contextSoil[2])), float.Parse(contextSoil[3]), Seeds.Null, false);
                                GlobalController.SoilList.Add(soil);
                            }
                            break;

                        case "PterocarpinTree":
                            string[]        contextPTree = rootPlayerSceneNode.InnerText.Split('|');
                            PterocarpinTree ptree        = new PterocarpinTree(new Map(contextPTree[0]), new Vector2(int.Parse(contextPTree
                                                                                                                               [1]), int.Parse(contextPTree[2])), ResourceController.Decorats_spring_tree, ResourceController.Decorats_tree_shadow, true);
                            ptree.GrowTime = float.Parse(contextPTree[3]);
                            GlobalController.PlayerSceneList.Add(ptree);
                            break;

                        case "Furniture":
                            string[] contextFurniture = rootPlayerSceneNode.InnerText.Split('|');
                            GlobalController.PlayerSceneList.Add(Furniture.CreateFurnitureFactory(new Map(contextFurniture[0]), new Vector2(int.Parse(contextFurniture
                                                                                                                                                      [1]), int.Parse(contextFurniture[2])), contextFurniture[3]));
                            break;

                        case "Construction":
                            string[] contextConstruction = rootPlayerSceneNode.InnerText.Split('|');
                            if (contextConstruction[3] == "cowhouse")
                            {
                                CowHouse cowHouse = Construction.CreateConstructionFactory(new Map(contextConstruction[0]), new Vector2(int.Parse(contextConstruction
                                                                                                                                                  [1]), int.Parse(contextConstruction[2])), contextConstruction[3]) as CowHouse;
                                cowHouse.Init(bool.Parse(contextConstruction[4]), int.Parse(contextConstruction[5]), bool.Parse(contextConstruction[6]));
                                GlobalController.PlayerSceneList.Add(cowHouse);
                            }

                            break;

                        case "Animals":
                            string[] contextAnimal = rootPlayerSceneNode.InnerText.Split('|');
                            if (contextAnimal[3] == "cow")
                            {
                                Cows cow = Animals.CreateAnimalsFactory(new Map(contextAnimal[0]), new Vector2(int.Parse(contextAnimal
                                                                                                                         [1]), int.Parse(contextAnimal[2])), contextAnimal[3], int.Parse(contextAnimal[5]), float.Parse(contextAnimal[6])) as Cows;
                                cow.Init(float.Parse(contextAnimal[4]));
                                GlobalController.AnimalsList.Add(cow);
                            }
                            break;

                        default:
                            break;
                        }
                    }
                    break;

                default:
                    break;
                }
            }

            foreach (IPlayerScene ipS in GlobalController.PlayerSceneList)
            {
                if (ipS.GetIntanceType() == "Construction")
                {
                    if ((ipS.GetInstance() as Construction).Name == "cowhouse")
                    {
                        CowHouse ch = ipS.GetInstance() as CowHouse;
                        GlobalController.AnimalsList.ForEach(u =>
                        {
                            if (u.GetIntanceType() == "Cows")
                            {
                                if ((u.GetInstance() as Cows).Id == ch.Id)
                                {
                                    ch.InitAnimal((u.GetInstance() as Cows));
                                }
                            }
                        });
                    }
                }
            }
            //GlobalController.OutdoorItemsList.Add(new OutDoorItem(new Map("village_suburb_west"),new Vector2(2400,1700), new Item("1", new Map("village_suburb_west"), new Vector2(1800, 1300), "water1", Content.Load<Texture2D>("Items/items"), 100)));
        }
예제 #6
0
    // Update is called once per frame

    void Update()
    {
        Vector3    mousePos   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector2    mousePos2D = new Vector2(mousePos.x, mousePos.y);
        Vector3Int mouseGrid  = movement.WorldToCell(mousePos);

        mouseGrid.z = 0;

        updateCamera();

        // If mouvement is processing continue the movement

        if (listOfMoves.Count > 0 && selectedCharacter != null)
        {
            if (selectedCharacter.transform.position == listOfMoves[listOfMoves.Count - 1])
            {
                listOfMoves.RemoveAt(listOfMoves.Count - 1);
                Vector3Int posOfPlayer = movement.WorldToCell(selectedCharacter.transform.position);
                posOfPlayer.z = 0;
                movement.SetTile(posOfPlayer, null);
                percentageOfMovement = 0;
                Vector3 groundTilePos = selectedCharacter.transform.position;
                groundTilePos.z = 0;
                selectedCharacter.GetComponent <Character>().RemoveMovementPoint((Instantiate(ground.GetTile(ground.WorldToCell(groundTilePos)) as GenericTile)).cost);
                if (listOfMoves.Count == 0)
                {
                    Vector3 characterPos = selectedCharacter.transform.position;
                    characterPos.z = 0;
                    characterLayer.SetTile(characterLayer.WorldToCell(characterPos), characterTile);
                    TileBase      t   = characterLayer.GetTile(characterLayer.WorldToCell(characterPos));
                    CharacterTile tmp = Instantiate(t) as CharacterTile;
                    tmp.character = selectedCharacter.gameObject;
                    characterLayer.SetTile(characterLayer.WorldToCell(characterPos), tmp);
                    canInteract       = true;
                    selectedCharacter = null;
                }
            }
            else
            {
                percentageOfMovement += 0.05f;
                selectedCharacter.transform.position = Vector3.Lerp(selectedCharacter.transform.position, listOfMoves[listOfMoves.Count - 1], percentageOfMovement);
            }
        }

        // Else player can play

        else if (attackAction == false && selectedCharacter != null && movement.GetTile(mouseGrid) != null && (Instantiate(movement.GetTile(mouseGrid)) as GenericTile) != null && (Instantiate(movement.GetTile(mouseGrid)) as GenericTile).pos != lastMovementPos)
        {
            lastMovementPos = (Instantiate(movement.GetTile(mouseGrid)) as GenericTile).pos;
            removeTakenPath();
            showTakenPath(Instantiate(movement.GetTile(mouseGrid)) as GenericTile);
        }
        else if (attackAction == false && selectedCharacter != null && movement.GetTile(mouseGrid) == null)
        {
            lastMovementPos = new Vector3Int(1000000, 1000000, 0);
            removeTakenPath();
        }
        if (Input.GetMouseButtonDown(0) && canInteract)
        {
            if (selectedCharacter != null)
            {
                Vector3Int mousePosGrid = movement.WorldToCell(selectedCharacter.transform.position);
                if (attackAction == false && movement.GetTile(new Vector3Int(mouseGrid.x, mouseGrid.y, 0)) != null)
                {
                    removePossibleMovement();
                    canInteract = false;
                    listOfMoves = listMoves(mouseGrid);
                    if (listOfMoves.Count <= 0)
                    {
                        canInteract       = true;
                        selectedCharacter = null;
                    }
                    else
                    {
                        Vector3Int characterLayerPos = characterLayer.WorldToCell(selectedCharacter.transform.position);
                        characterLayerPos.z = 0;
                        characterLayer.SetTile(characterLayerPos, null);
                    }
                }
                else if (attackAction && movement.GetTile(new Vector3Int(mouseGrid.x, mouseGrid.y, 0)) != null && characterLayer.GetTile(new Vector3Int(mouseGrid.x, mouseGrid.y, 0)) != null &&
                         (Instantiate(characterLayer.GetTile(new Vector3Int(mouseGrid.x, mouseGrid.y, 0))) as CharacterTile).character.GetComponent <Character>().ally != selectedCharacter.GetComponent <Character>().ally)
                {
                    Vector3Int characterLayerPos = characterLayer.WorldToCell(selectedCharacter.transform.position);
                    characterLayerPos.z = 0;
                    CharacterTile tmp = Instantiate(characterLayer.GetTile(new Vector3Int(mouseGrid.x, mouseGrid.y, 0))) as CharacterTile;
                    if (tmp.character.GetComponent <Ressuractable>() != null && tmp.character.GetComponent <Ressuractable>().canBeRessurected&& selectedCharacter.GetComponent <Character>().necromancer == true)
                    {
                        tmp.character.GetComponent <Ressuractable>().Ressurect();
                    }
                    else if (tmp.character.GetComponent <Ressuractable>() == null || (tmp.character.GetComponent <Ressuractable>() != null && !tmp.character.GetComponent <Ressuractable>().canBeRessurected))
                    {
                        GenericTile attackerTile = Instantiate(ground.GetTile(ground.WorldToCell(new Vector3(selectedCharacter.transform.position.x, selectedCharacter.transform.position.y, 0)))) as GenericTile;
                        GenericTile opponentTile = Instantiate(ground.GetTile(ground.WorldToCell(new Vector3(mousePos.x, mousePos.y, 0)))) as GenericTile;

                        SimulateAttack(selectedCharacter, attackerTile, tmp.character, opponentTile);
                    }
                    selectedCharacter.GetComponent <Character>().canAttacked = false;
                    removePossibleAttack();
                    removePossibleMovement();
                    removeTakenMovement();
                    selectedCharacter = null;
                }
                else
                {
                    removePossibleMovement();
                    removeTakenMovement();
                    removePossibleAttack();
                    selectedCharacter = null;
                    attackAction      = false;
                }
            }
            else
            {
                RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero);
                if (hit.collider != null)
                {
                    selectedCharacter = hit.collider.gameObject;
                    if (selectedCharacter.GetComponent <Character>().ally == true && selectedCharacter.GetComponent <Character>().actualMovementPoint > 0)
                    {
                        showMovementOfPlayer();
                    }
                    else
                    {
                        selectedCharacter = null;
                    }
                }
            }
        }
        if (Input.GetMouseButtonDown(1) && canInteract)
        {
            if (selectedCharacter != null)
            {
                removePossibleMovement();
                removeTakenMovement();
                removePossibleAttack();
                selectedCharacter = null;
                attackAction      = false;
            }
            else
            {
                RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero);
                if (hit.collider != null)
                {
                    selectedCharacter = hit.collider.gameObject;
                    if (selectedCharacter.GetComponent <Character>().ally == true && selectedCharacter.GetComponent <Character>().canAttacked)
                    {
                        showAttackOfPlayer();
                        attackAction = true;
                    }
                    else
                    {
                        selectedCharacter = null;
                    }
                }
            }
        }
    }
예제 #7
0
        public CharacterSelectState(Game1 game, GraphicsDevice graphicsDevice, ContentManager content) : base(game, graphicsDevice, content)
        {
            var characterPlateTexture = _content.Load <Texture2D>("Character Select/Character Slot");
            var characterTestTexture  = _content.Load <Texture2D>("Character Sheets/Ninja M");

            var characterPlate1 = new CharacterTile(characterPlateTexture, characterTestTexture)
            {
                Position = new Vector2(333, 100)
            };

            var characterPlate2 = new CharacterTile(characterPlateTexture, characterTestTexture)
            {
                Position = new Vector2(533, 100)
            };

            var characterPlate3 = new CharacterTile(characterPlateTexture, characterTestTexture)
            {
                Position = new Vector2(733, 100)
            };

            var characterPlate4 = new CharacterTile(characterPlateTexture, characterTestTexture)
            {
                Position = new Vector2(933, 100)
            };

            var characterPlate5 = new CharacterTile(characterPlateTexture, characterTestTexture)
            {
                Position = new Vector2(333, 250)
            };

            var characterPlate6 = new CharacterTile(characterPlateTexture, characterTestTexture)
            {
                Position = new Vector2(533, 250)
            };

            var characterPlate7 = new CharacterTile(characterPlateTexture, characterTestTexture)
            {
                Position = new Vector2(733, 250)
            };

            var characterPlate8 = new CharacterTile(characterPlateTexture, characterTestTexture)
            {
                Position = new Vector2(933, 250)
            };

            var characterPlate9 = new CharacterTile(characterPlateTexture, characterTestTexture)
            {
                Position = new Vector2(333, 400)
            };

            var characterPlate10 = new CharacterTile(characterPlateTexture, characterTestTexture)
            {
                Position = new Vector2(533, 400)
            };

            var characterPlate11 = new CharacterTile(characterPlateTexture, characterTestTexture)
            {
                Position = new Vector2(733, 400)
            };

            var characterPlate12 = new CharacterTile(characterPlateTexture, characterTestTexture)
            {
                Position = new Vector2(933, 400)
            };

            var backgroundTexture = _content.Load <Texture2D>("Menu Backgrounds/2");

            var backgroundBackground = new Background(backgroundTexture);

            _components = new List <Component>
            {
                backgroundBackground,
                characterPlate1,
                characterPlate2,
                characterPlate3,
                characterPlate4,
                characterPlate5,
                characterPlate6,
                characterPlate7,
                characterPlate8,
                characterPlate9,
                characterPlate10,
                characterPlate11,
                characterPlate12,
            };
        }
예제 #8
0
        private static Dictionary <Color, Color> FillColorCacheByGroup(CharacterTile characterTile, int group, string paletteId)
        {
            Color nullColor = Util.NullColor;

            BankModel bankModel = ProjectFiles.GetModel <BankModel>(characterTile.BankID);

            PaletteModel paletteModel = ProjectFiles.GetModel <PaletteModel>(paletteId);

            Dictionary <Color, Color> colors = new Dictionary <Color, Color>()
            {
                { nullColor, nullColor }
            };

            foreach (PTTileModel tile in bankModel.PTTiles)
            {
                if (string.IsNullOrEmpty(tile.GUID))
                {
                    continue;
                }

                if (tile.Group != group)
                {
                    continue;
                }

                TileSetModel model = ProjectFiles.GetModel <TileSetModel>(tile.TileSetID);

                if (model == null)
                {
                    continue;
                }

                if (!TileSetModel.BitmapCache.TryGetValue(tile.TileSetID, out WriteableBitmap tileSetBitmap))
                {
                    continue;
                }

                WriteableBitmap cropped = tileSetBitmap.Crop((int)tile.Point.X, (int)tile.Point.Y, 8, 8);

                for (int y = 0; y < 8; ++y)
                {
                    for (int x = 0; x < 8; ++x)
                    {
                        Color color = cropped.GetPixel(x, y);
                        color.A = 255;

                        if (!colors.TryGetValue(color, out Color newColor))
                        {
                            if (paletteModel == null)
                            {
                                newColor = nullColor;
                            }
                            else
                            {
                                switch (colors.Count)
                                {
                                case 1: newColor = Util.GetColorFromInt(paletteModel.Color1); break;

                                case 2: newColor = Util.GetColorFromInt(paletteModel.Color2); break;

                                case 3: newColor = Util.GetColorFromInt(paletteModel.Color3); break;
                                }
                            }

                            colors.Add(color, newColor);
                        }
                    }
                }
            }

            return(colors);
        }