Exemplo n.º 1
0
    public void Kill(CustomPiece p)
    {
        AllPieces.Remove(p);
        p.Pos.Exit(p);

        switch (p.Side)
        {
        case "White":
            if (White.All.Contains(p))
            {
                White.All.Remove(p);
            }

            p.gameObject.transform.parent = WhiteSide.transform;
            whiteSideCount++;
            p.gameObject.transform.localPosition = SidePos(whiteSideCount, 1);
            break;

        case "Black":
            if (Black.All.Contains(p))
            {
                Black.All.Remove(p);
            }

            p.gameObject.transform.parent = BlackSide.transform;
            blackSideCount++;
            p.gameObject.transform.localPosition = SidePos(blackSideCount, -1);
            break;
        }

        p.Pos.Graves.Add(p);
        p.Grave   = p.Pos;
        p.enabled = false;
    }
Exemplo n.º 2
0
    public bool CanRevive()
    {
        if (Pos.Graves.Count > 0)
        {
            CustomPiece revive = null;

            Pos.Graves.Reverse();

            foreach (CustomPiece p in Pos.Graves)
            {
                if (p.Side == Side)
                {
                    revive = p;
                }
            }

            if (revive)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }

        return(false);
    }
Exemplo n.º 3
0
    public void Selected(CustomPiece Target)
    {
        SelectImage.gameObject.SetActive(true);

        SelectImage.sprite = Resources.Load <Sprite>(Target.name.Split(' ')[0] + "/" + Target.name.Split(' ')[1]);
        PlayAnim(SelectAnim, true);

        SelectedText.text = Target.Ability;

        if (Target.Ability == "")
        {
            SelectedButton.gameObject.SetActive(false);
        }
        else
        {
            SelectedText.gameObject.SetActive(true);

            SelectedButton.gameObject.SetActive(true);
            SelectedButton.onClick.RemoveAllListeners();
            SelectedButton.onClick.AddListener(() => ToggleExpand());

            if (Target.Ability == "")
            {
                SelectedExpand.text = Abilities.Movements[Target.Type];
            }
            else
            {
                SelectedExpand.text = Abilities.AbilityDescriptions[Target.Ability];
            }


            AbilityButton.gameObject.SetActive(Target.OnClick());
        }
    }
Exemplo n.º 4
0
        internal void RegisterPiece()
        {
            logger.LogInfo("Registering Seed Totem Piece");
            Texture2D iconTexture = AssetUtils.LoadTexture(SeedTotemMod.GetAssetPath(iconPath));
            Sprite    iconSprite  = null;

            if (iconTexture == null)
            {
                logger.LogWarning("Icon missing, should be at " + iconPath + ", using default icon instead ");
            }
            else
            {
                iconSprite = Sprite.Create(iconTexture, new Rect(0f, 0f, iconTexture.width, iconTexture.height), Vector2.zero);
            }
            PieceConfig pieceConfig = new PieceConfig()
            {
                PieceTable   = configLocation.GetSerializedValue(),
                Description  = "$piece_seed_totem_description",
                Requirements = LoadJsonFile(SeedTotemMod.GetAssetPath("seed-totem-custom-requirements.json"))
            };

            if (iconSprite)
            {
                pieceConfig.Icon = iconSprite;
            }

            CustomPiece customPiece = new CustomPiece(Prefab, pieceConfig);

            PieceManager.Instance.AddPiece(customPiece);
        }
Exemplo n.º 5
0
    public CustomPiece Revive(Tile to)
    {
        if (Pos.Graves.Count > 0)
        {
            CustomPiece revive = null;

            Pos.Graves.Reverse();

            foreach (CustomPiece p in Pos.Graves)
            {
                if (p.Side == Side)
                {
                    revive = p;
                }
            }

            if (revive)
            {
                Game.M.Revive(revive, to);
                return(revive);
            }
            else
            {
                return(null);
            }
        }

        return(null);
    }
Exemplo n.º 6
0
        /// <summary>
        ///     Add a <see cref="CustomPiece"/> to the game.<br />
        ///     Checks if the custom piece is valid and unique and adds it to the list of custom pieces.<br />
        ///     Custom pieces are added to their respective <see cref="PieceTable"/>s after <see cref="ObjectDB.Awake"/>.
        /// </summary>
        /// <param name="customPiece">The custom piece to add.</param>
        /// <returns>true if the custom piece was added to the manager.</returns>
        public bool AddPiece(CustomPiece customPiece)
        {
            if (!customPiece.IsValid())
            {
                Logger.LogWarning($"Custom piece {customPiece} is not valid");
                return(false);
            }
            if (Pieces.Contains(customPiece))
            {
                Logger.LogWarning($"Custom piece {customPiece} already added");
                return(false);
            }

            // Add to the right layer if necessary
            if (customPiece.PiecePrefab.layer == 0)
            {
                customPiece.PiecePrefab.layer = LayerMask.NameToLayer("piece");
            }

            // Add the prefab to the PrefabManager
            PrefabManager.Instance.AddPrefab(customPiece.PiecePrefab);

            // Add the custom piece to the PieceManager
            Pieces.Add(customPiece);

            return(true);
        }
Exemplo n.º 7
0
    void BlockCheck(CustomPiece King)
    {
        CheckBlockable = false;
        List <CustomPiece> temp = null;

        switch (King.Side)
        {
        case "White":
            temp = White.All;
            break;

        case "Black":
            temp = Black.All;
            break;
        }

        foreach (CustomPiece p in temp)
        {
            foreach (Tile t in p.Path)
            {
                if (AttackPath.Contains(t) || King.Checker.Pos == t)
                {
                    CheckBlockable = true;
                }
            }
        }
    }
Exemplo n.º 8
0
        private void Awake()
        {
            // Do all your init stuff here
            // Acceptable value ranges can be defined to allow configuration via a slider in the BepInEx ConfigurationManager: https://github.com/BepInEx/BepInEx.ConfigurationManager
            Config.Bind <int>("Main Section", "Example configuration integer", 1, new ConfigDescription("This is an example config, using a range limitation for ConfigurationManager", new AcceptableValueRange <int>(0, 100)));

            // Jotunn comes with its own Logger class to provide a consistent Log style for all mods using it
            Jotunn.Logger.LogInfo("ModStub has landed");

            CustomPiece cpHeart    = null;
            CustomPiece cpExpander = null;

            cpHeart.Piece.m_craftingStation = PrefabManager.Cache.GetPrefab <CraftingStation>("piece_workbench");
            CraftingStation customCraftingStation = cpHeart.PiecePrefab.AddComponent <CraftingStation>();

            customCraftingStation.m_name = "$piece_TS_Expander_CS";

            cpExpander.Piece.m_craftingStation = customCraftingStation;
            cpExpander.Piece.m_resources       = new Piece.Requirement[] {
                MockRequirement.Create("Stone", 10),
                MockRequirement.Create("Wood", 10)
            };
            cpExpander.PiecePrefab.AddComponent <CraftingStation>();
            cpExpander.PiecePrefab.GetComponent <CraftingStation>().m_name       = "$piece_TS_Expander_CS";
            cpExpander.PiecePrefab.GetComponent <CraftingStation>().m_rangeBuild = 45; // 50 or 45 - the range is for the player *not* the piece.
        }
Exemplo n.º 9
0
        // Implementation of pieces via configs.
        private void CreateRunePieces()
        {
            // Create and add custom pieces
            var makebp_prefab = blueprintRuneBundle.LoadAsset <GameObject>("make_blueprint");
            var makebp        = new CustomPiece(makebp_prefab,
                                                new PieceConfig
            {
                PieceTable = "_BlueprintPieceTable"
            });

            PieceManager.Instance.AddPiece(makebp);

            var placebp_prefab = blueprintRuneBundle.LoadAsset <GameObject>("piece_blueprint");
            var placebp        = new CustomPiece(placebp_prefab,
                                                 new PieceConfig
            {
                PieceTable        = "_BlueprintPieceTable",
                AllowedInDungeons = true,
                Requirements      = new[]
                {
                    new RequirementConfig {
                        Item = "Wood", Amount = 2
                    }
                }
            });

            PieceManager.Instance.AddPiece(placebp);
            BlueprintRuneLocalizations();
        }
Exemplo n.º 10
0
 public void Cast(string effect)
 {
     TargetPiece = Game.M.AbilityTarget;
     TargetTile  = Game.M.AbilityPosition;
     TargetPos   = TargetTile.transform.position;
     StartCoroutine(CastingTick(effect));
 }
Exemplo n.º 11
0
 public void ToggleAbilityButton(UnityEngine.Events.UnityAction call, CustomPiece piece)
 {
     AbilityButton.gameObject.SetActive(true);
     AbilityButton.onClick.RemoveAllListeners();
     AbilityButton.onClick.AddListener(call);
     AbilityButton.onClick.AddListener(() => AbilityButton.gameObject.SetActive(false));
 }
Exemplo n.º 12
0
    public void Revive(CustomPiece p, Tile location)
    {
        p.enabled = true;
        p.Grave.Graves.Remove(p);
        p.Grave = null;

        AllPieces.Add(p);
        location.Enter(p);

        switch (p.Side)
        {
        case "White":
            White.All.Add(p);

            p.gameObject.transform.parent = White.King.transform.parent;
            whiteSideCount--;
            p.gameObject.transform.position = location.transform.position;
            break;

        case "Black":
            Black.All.Add(p);

            p.gameObject.transform.parent = Black.King.transform.parent;
            blackSideCount--;
            p.gameObject.transform.position = location.transform.position;
            break;
        }
    }
Exemplo n.º 13
0
    void SwapPos(CustomPiece target)
    {
        int x = PosX;
        int y = PosY;

        target.Pos.Enter(this);
        Tiles[x, y].Enter(target);
    }
Exemplo n.º 14
0
 public void Exit(Piece p)
 {
     if (Occupier)
     {
         if (Occupier.Equals(p))
         {
             Occupier = null;
         }
     }
 }
Exemplo n.º 15
0
 public List <Tile> QueenLOS(CustomPiece King)
 {
     if (King.PosX == PosX || King.PosY == PosY)
     {
         return(RookLOS(King));
     }
     else
     {
         return(BishopLOS(King));
     }
 }
Exemplo n.º 16
0
    public void Enter(Piece piece)
    {
        if (piece.Pos)
        {
            piece.Pos.Exit(piece);
        }

        Occupier      = piece.GetComponent <CustomPiece>();
        Occupier.Pos  = this;
        Occupier.PosY = PosY;
        Occupier.PosX = PosX;
    }
Exemplo n.º 17
0
        // Implementation of stub objects
        private void AddEmptyPiece()
        {
            CustomPiece CP = new CustomPiece("$piece_lul", "Hammer");

            if (CP != null)
            {
                var piece = CP.Piece;
                piece.m_icon = testSprite;
                var prefab = CP.PiecePrefab;
                prefab.GetComponent <MeshRenderer>().material.mainTexture = testTex;
                PieceManager.Instance.AddPiece(CP);
            }
        }
Exemplo n.º 18
0
    private void Start()
    {
        Self      = GetComponent <CustomPiece>();
        Anim      = GetComponentInChildren <Animator>();
        TargetPos = transform.position;
        GetClipTimes();

        if (Shield)
        {
            Anim.SetBool("Shielded", Self.Ability == "Shielded");
            Shield.SetActive(Self.Ability == "Shielded");
        }
    }
Exemplo n.º 19
0
    bool Castling(CustomPiece Rook)
    {
        if (Rook.PosX != Rook.startingX)
        {
            return(false);
        }


        foreach (Tile t in Rook.RookLOS((CustomPiece)this))
        {
            if (t.Occupier && t.Occupier.Type != "Rook" && t.Occupier != this)
            {
                return(false);
            }
        }

        List <Tile> temp = new List <Tile>();
        bool        left = Rook.PosX < PosX;

        for (int i = -2; i < 0; i++)
        {
            if (left)
            {
                temp.Add(Tiles[PosX + i, PosY]);
            }
            else
            {
                temp.Add(Tiles[PosX - i, PosY]);
            }
        }

        foreach (Tile t in temp)
        {
            if (!t.Safe)
            {
                return(false);
            }
        }

        Path.Add(temp[0]);
        if (left)
        {
            CastleLeft = new System.Tuple <CustomPiece, List <Tile> >(Rook, temp);
        }
        else if (!left)
        {
            CastleRight = new System.Tuple <CustomPiece, List <Tile> >(Rook, temp);
        }

        return(true);
    }
Exemplo n.º 20
0
        private void AddInvalidItems()
        {
            CustomItem CI = new CustomItem("item_faulty", false);

            if (CI != null)
            {
                CI.ItemDrop.m_itemData.m_shared.m_icons = new Sprite[]
                {
                    testSprite
                };
                ItemManager.Instance.AddItem(CI);

                CustomRecipe CR = new CustomRecipe(new RecipeConfig
                {
                    Item         = "item_faulty",
                    Requirements = new RequirementConfig[]
                    {
                        new RequirementConfig {
                            Item = "NotReallyThereResource", Amount = 99
                        }
                    }
                });
                ItemManager.Instance.AddRecipe(CR);
            }

            CustomPiece CP = new CustomPiece("piece_fukup", "Hammer");

            if (CP != null)
            {
                var piece = CP.Piece;
                piece.m_icon = testSprite;
                var prefab = CP.PiecePrefab;

                // Test faulty resource, do it manually cause there is no config on empty pieces atm
                var cfg = new PieceConfig
                {
                    Requirements = new RequirementConfig[]
                    {
                        new RequirementConfig {
                            Item = "StillNotThereResource", Amount = 99
                        }
                    }
                };
                cfg.Apply(prefab);
                CP.FixReference = true;

                PieceManager.Instance.AddPiece(CP);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        ///     Remove a custom piece by its ref.
        /// </summary>
        /// <param name="piece"><see cref="CustomPiece"/> to remove.</param>
        public void RemovePiece(CustomPiece piece)
        {
            if (!Pieces.Contains(piece))
            {
                Logger.LogWarning($"Could not remove piece {piece}: Not found");
                return;
            }

            Pieces.Remove(piece);

            if (piece.PiecePrefab && PrefabManager.Instance.GetPrefab(piece.PiecePrefab.name))
            {
                PrefabManager.Instance.RemovePrefab(piece.PiecePrefab.name);
            }
        }
Exemplo n.º 22
0
 private void AddCustomPrefabs()
 {
     try
     {
         airshipPiece = new CustomPiece("AirshipBase", "wood_floor", "Hammer");
         airshipPiece.Piece.m_category    = Piece.PieceCategory.Misc;
         airshipPiece.Piece.m_name        = "$item_airshipbase";
         airshipPiece.Piece.m_description = "$item_airshipbase_desc";
         airshipPiece.Piece.m_waterPiece  = true;
         PieceManager.Instance.AddPiece(airshipPiece);
     } finally
     {
         ItemManager.OnVanillaItemsAvailable -= AddCustomPrefabs;
     }
 }
Exemplo n.º 23
0
    public List <Tile> LineOfSight(CustomPiece King)
    {
        switch (Type)
        {
        case "Rook":
            return(RookLOS(King));

        case "Bishop":
            return(BishopLOS(King));

        case "Queen":
            return(QueenLOS(King));
        }

        return(new List <Tile>());
    }
Exemplo n.º 24
0
    public void Clear()
    {
        if (Selected)
        {
            Selected.Unselect();
        }

        TargetTile      = null;
        AbilityTarget   = null;
        AbilityPosition = null;

        NeedPos = false;

        SearchingPiece = false;
        SearchingPos   = false;
    }
Exemplo n.º 25
0
        private static void InitializePiece(String key, String name, String desc)
        {
            CustomPiece CP = new CustomPiece(key, "piece_chest_wood", "Hammer");

            CP.Piece.m_name        = name;
            CP.Piece.m_description = desc;
            CP.Piece.m_resources   = new Piece.Requirement[]
            {
                new Piece.Requirement()
                {
                    m_resItem = PrefabManager.Cache.GetPrefab <ItemDrop>("Wood"),
                    m_amount  = 1
                }
            };
            PieceManager.Instance.AddPiece(CP);
        }
Exemplo n.º 26
0
        private static void CreatePrefabPiece(GameObject prefab)
        {
            InitPieceData(prefab);

            var pieceConfig = new PieceConfig
            {
                Name              = prefab.name,
                Description       = GetPrefabFriendlyName(prefab),
                PieceTable        = "_HammerPieceTable",
                Category          = GetPrefabCategory(prefab),
                AllowedInDungeons = true,
                Icon              = CreatePrefabIcon(prefab)
            };

            var piece = new CustomPiece(prefab, true, pieceConfig);

            PieceManager.Instance.AddPiece(piece);
        }
Exemplo n.º 27
0
    public void CheckPinning()
    {
        bool        KingInPath   = false;
        CustomPiece PieceInPath  = null;
        int         piecesInPath = 0;
        CustomPiece EnemyKing    = null;

        switch (Side)
        {
        case "White":
            EnemyKing = Game.Black.King;
            break;

        case "Black":
            EnemyKing = Game.White.King;
            break;
        }

        List <Tile> TempList = LineOfSight(EnemyKing);

        foreach (Tile t in FullPath())
        {
            if (t.Occupier && t.Occupier.Side != Side)
            {
                if (t.Occupier.Type == "King")
                {
                    KingInPath = true;
                }
                else
                {
                    if (TempList.Contains(t))
                    {
                        PieceInPath = t.Occupier;
                        piecesInPath++;
                    }
                }
            }
        }

        if (KingInPath && PieceInPath && piecesInPath == 1)
        {
            PieceInPath.PinnedMovement(TempList);
        }
    }
Exemplo n.º 28
0
    private IEnumerator CastingTick(string effect)
    {
        //Face Target
        if (Vector3.Distance(Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(TargetPos - transform.position), TurnSpeed * Time.deltaTime).eulerAngles, Quaternion.LookRotation(TargetPos - transform.position).eulerAngles) > 2)
        {
            transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(TargetPos - transform.position), TurnSpeed * Time.deltaTime);
            yield return(new WaitForEndOfFrame());

            StartCoroutine(CastingTick(effect));
        }
        else
        {
            Anim.SetBool("Moving", false);
            Anim.SetBool("Casting", true);
            yield return(new WaitForSeconds(ClipTimes["Cast"] * 0.8f));

            Anim.SetBool("Casting", false);

            switch (effect)
            {
            case "Injure":
                TargetPiece.Injured = true;
                break;

            case "Teleport":
                if (TargetTile.Occupier)
                {
                    TargetTile.Occupier.MC.Attacked(0);
                }

                TargetTile.Enter(TargetPiece);
                TargetPiece.MC.Teleport(false, TargetTile.transform.position);

                yield return(new WaitForSeconds(TargetPiece.MC.ClipTimes["Crouch"] * 2));

                break;
            }

            TargetPiece = null;

            Game.M.NextTurn();
        }
    }
Exemplo n.º 29
0
        /// you will care about copying basically this chunk of code right here
        private void PlantMaker()                                                   //this is the function name you need to change it
        {
            var planterthing = plants.LoadAsset <GameObject>("custompiece_orchid"); //this defines the prefab name in your uniy project
            // you need to change planterthing and planter every time you copy this
            var planter = new CustomPiece(planterthing,
                                          new PieceConfig
            {
                PieceTable        = "_PlantitPieceTable",
                AllowedInDungeons = false,
                Requirements      = new[]
                {
                    new RequirementConfig {
                        Item = "Wood", Amount = 2, Recover = true
                    }
                }
            });

            PieceManager.Instance.AddPiece(planter);
        }
Exemplo n.º 30
0
    public List <Tile> BishopLOS(CustomPiece King)
    {
        List <Tile> path = new List <Tile>();

        if (King.Pos.PosY == PosY || King.Pos.PosX == PosX)
        {
            return(path);
        }
        else if (King.Pos.PosY > PosY) //below
        {
            if (King.Pos.PosX > PosX)  //right
            {
                path = SeePath(1, 1);
            }
            else if (King.Pos.PosX < PosX) //left
            {
                path = SeePath(-1, 1);
            }
        }
        else if (King.Pos.PosY < PosY) //above
        {
            if (King.Pos.PosX > PosX)  //right
            {
                path = SeePath(1, -1);
            }
            else if (King.Pos.PosX < PosX) //left
            {
                path = SeePath(-1, -1);
            }
        }

        if (path.Contains(King.Pos))
        {
            return(path);
        }
        else
        {
            path.Clear();
        }

        return(path);
    }