コード例 #1
0
    public static MechaComponentBase BaseInitialize(MechaComponentInfo mechaComponentInfo, Mecha parentMecha)
    {
        MechaComponentBase mcb = GameObjectPoolManager.Instance.MechaComponentPoolDict[mechaComponentInfo.MechaComponentType].AllocateGameObject <MechaComponentBase>(parentMecha ? parentMecha.transform : null);

        mcb.Initialize(mechaComponentInfo, parentMecha);
        return(mcb);
    }
コード例 #2
0
    public void RemoveMechaComponent(MechaComponentBase mcb)
    {
        if (mechaComponents.Contains(mcb))
        {
            mechaComponents.Remove(mcb);
            if (MechaInfo.MechaType == MechaType.Self && mcb.MechaComponentInfo.MechaComponentType == MechaComponentType.Core)
            {
                RefreshHUDPanelCoreLifeSliderCount?.Invoke();
            }

            RefreshMechaMatrix(out List <MechaComponentBase> _, out List <MechaComponentBase> isolatedComponents);
            if (MechaInfo.MechaType == MechaType.Enemy)
            {
                foreach (MechaComponentBase m in isolatedComponents)
                {
                    int  ran  = Random.Range(0, 100);
                    bool drop = ran < m.MechaComponentInfo.DropProbability;
                    if (drop)
                    {
                        MechaComponentDropSprite mcds = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.MechaComponentDropSprite].AllocateGameObject <MechaComponentDropSprite>(BattleManager.Instance.MechaComponentDropSpriteContainer);
                        mcds.Initialize(m.MechaComponentInfo, m.transform.position);
                    }

                    mechaComponents.Remove(m);
                    mcb.MechaComponentGrids.SetIsolatedIndicatorShown(true);
                    m.PoolRecycle(1f);
                }
            }

            if (mechaComponents.Count == 0)
            {
                Die();
            }
        }
    }
コード例 #3
0
    public override void ExertEffectOnOtherComponents()
    {
        base.ExertEffectOnOtherComponents();
        MechaComponentBase mcb  = BattleManager.Instance.PlayerMecha.GetMechaComponent <IBuff_PowerUp>();
        MechaComponentBuff buff = new MechaComponentBuff(typeof(IBuff_PowerUp), this, mcb, new Modifier(2, Sign.Multiply));

        buff.AddBuff();
    }
コード例 #4
0
    private void AddCoreLifeSlider(MechaComponentBase mcb)
    {
        HUDSlider hudSlider = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.HUDSlider].AllocateGameObject <HUDSlider>(CoreLifeSliderContainer);

        hudSlider.Initialize(1f, CoreLifeSliderColor, out mcb.OnLifeChange);
        hudSlider.SetValue(mcb.M_LeftLife, mcb.M_TotalLife);
        Core_HUDSliders.Add(hudSlider);
    }
コード例 #5
0
    private void AddIsolatedComponentIndicator(GridPos gp_matrix)
    {
        MechaComponentBase mcb = mechaComponentMatrix[gp_matrix.z, gp_matrix.x];

        if (mcb)
        {
            mcb.MechaComponentGrids.SetIsolatedIndicatorShown(true);
        }
    }
コード例 #6
0
    private void AddForbidComponentIndicator(GridPos gp_matrix)
    {
        MechaComponentBase mcb = mechaComponentMatrix[gp_matrix.z, gp_matrix.x];

        if (mcb)
        {
            GridPos gp = gp_matrix.ConvertMatrixIndexToGridPos();
            GridPos gp_local_noRotate = gp - mcb.MechaComponentInfo.GridPos;
            GridPos gp_local_rotate   = GridPos.RotateGridPos(gp_local_noRotate, (GridPos.Orientation)((4 - (int)mcb.MechaComponentInfo.GridPos.orientation) % 4));
            mcb.MechaComponentGrids.SetForbidIndicatorShown(true, gp_local_rotate);
        }
    }
コード例 #7
0
    public MechaComponentBuff(Type buffTYpe, MechaComponentBase source, MechaComponentBase target, Modifier modifier)
    {
        BuffType = buffTYpe;
        if (target.GetType().GetInterface(BuffType.Name) != null)
        {
            TargetIBuff = (IBuff)target;
        }

        Source = source;
        Target = target;

        Modifier = modifier;
    }
コード例 #8
0
    public void AddMechaComponent(MechaComponentBase mcb)
    {
        mechaComponents.Add(mcb);
        if (MechaInfo.MechaType == MechaType.Self && mcb.MechaComponentInfo.MechaComponentType == MechaComponentType.Core)
        {
            RefreshHUDPanelCoreLifeSliderCount?.Invoke();
        }

        mcb.transform.SetParent(MechaComponentContainer);
        mcb.MechaComponentGrids.SetGridShown(GridShown);
        mcb.MechaComponentGrids.SetSlotLightsShown(SlotLightsShown);
        mcb.MechaComponentGrids.TurnOffAllForbidIndicator();
        mcb.MechaComponentGrids.SetIsolatedIndicatorShown(false);
        RefreshMechaMatrix();
    }
コード例 #9
0
    /// <summary>
    /// Load all prefabs to see which grids does a mecha component take
    /// </summary>
    private void LoadBlockOccupiedGridInfo()
    {
        MechaComponentOccupiedGridPosDict.Clear();
        List <MechaComponentBase> mcbs = new List <MechaComponentBase>();

        foreach (string s in Enum.GetNames(typeof(MechaComponentType)))
        {
            MechaComponentType mcType = (MechaComponentType)Enum.Parse(typeof(MechaComponentType), s);
            MechaComponentBase mcb    = MechaComponentBase.BaseInitialize(new MechaComponentInfo(mcType, new GridPos(0, 0, GridPos.Orientation.Up), 10, 0), null);
            mcbs.Add(mcb);
            MechaComponentOccupiedGridPosDict.Add(mcType, CloneVariantUtils.List(mcb.MechaComponentGrids.MechaComponentGridPositions));
        }

        foreach (MechaComponentBase mcb in mcbs)
        {
            DestroyImmediate(mcb.gameObject);
        }
    }
コード例 #10
0
ファイル: BagItem.cs プロジェクト: dqchess/RoguelikeMechaGame
    public void DragComponent_DragOutEffects()
    {
        MechaComponentBase mcb = MechaComponentBase.BaseInitialize(new MechaComponentInfo(MechaComponentInfo.MechaComponentType, new GridPos(0, 0), MechaComponentInfo.TotalLife, 0), BattleManager.Instance.PlayerMecha);
        GridPos            gp  = GridPos.GetGridPosByMousePos(BattleManager.Instance.PlayerMecha.transform, Vector3.up, GameManager.GridSize);

        mcb.SetGridPosition(gp);
        BattleManager.Instance.PlayerMecha.AddMechaComponent(mcb);
        DragManager.Instance.CancelCurrentDrag();
        DragManager.Instance.CurrentDrag = mcb.Draggable;
        mcb.Draggable.IsOnDrag           = true;
        BagManager.Instance.RemoveMechaComponentFromBag(this, false);
        PoolRecycle();

        if (BagManager.Instance.InfiniteComponents)
        {
            BagManager.Instance.AddMechaComponentToBag(MechaComponentInfo, out BagItem _);
        }
    }
コード例 #11
0
    public void RefreshMechaMatrix(out List <MechaComponentBase> conflictComponents, out List <MechaComponentBase> isolatedComponents)
    {
        foreach (MechaComponentBase mcb in mechaComponents)
        {
            mcb.MechaComponentGrids.SetIsolatedIndicatorShown(false);
            mcb.MechaComponentGrids.TurnOffAllForbidIndicator();
        }

        List <GridPos>            coreGPs = new List <GridPos>();
        List <MechaComponentBase> notConflictComponents = new List <MechaComponentBase>();

        // Find conflict components
        List <GridPos> conflictGridPositions = new List <GridPos>();

        conflictComponents = new List <MechaComponentBase>();

        for (int z = 0; z < mechaComponentMatrix.GetLength(0); z++)
        {
            for (int x = 0; x < mechaComponentMatrix.GetLength(1); x++)
            {
                mechaComponentMatrix[z, x] = null;
            }
        }

        foreach (MechaComponentBase mcb in mechaComponents)
        {
            bool isCore      = mcb.MechaComponentInfo.MechaComponentType == MechaComponentType.Core;
            bool hasConflict = false;
            foreach (GridPos gp in mcb.MechaComponentInfo.OccupiedGridPositions)
            {
                GridPos gp_matrix = gp.ConvertGridPosToMatrixIndex();

                if (gp_matrix.x < 0 || gp_matrix.x >= mechaComponentMatrix.GetLength(1) ||
                    gp_matrix.z < 0 || gp_matrix.z >= mechaComponentMatrix.GetLength(0))
                {
                    hasConflict = true;
                    conflictGridPositions.Add(gp_matrix);
                }
                else
                {
                    if (mechaComponentMatrix[gp_matrix.z, gp_matrix.x] != null)
                    {
                        hasConflict = true;
                        conflictGridPositions.Add(gp_matrix);
                    }
                    else
                    {
                        mechaComponentMatrix[gp_matrix.z, gp_matrix.x] = mcb;
                        if (isCore)
                        {
                            coreGPs.Add(gp_matrix);
                        }
                    }
                }
            }

            if (hasConflict)
            {
                conflictComponents.Add(mcb);
            }
            else
            {
                notConflictComponents.Add(mcb);
            }
        }

        foreach (GridPos gp in conflictGridPositions)
        {
            AddForbidComponentIndicator(gp);
        }

        // Find isolated components
        List <GridPos> isolatedGridPositions = new List <GridPos>();

        isolatedComponents = new List <MechaComponentBase>();

        int[,] connectedMatrix = new int[ConfigManager.EDIT_AREA_SIZE * 2 + 1, ConfigManager.EDIT_AREA_SIZE * 2 + 1];

        foreach (MechaComponentBase mcb in notConflictComponents)
        {
            foreach (GridPos gp in mcb.MechaComponentInfo.OccupiedGridPositions)
            {
                GridPos gp_matrix = gp.ConvertGridPosToMatrixIndex();
                connectedMatrix[gp_matrix.z, gp_matrix.x] = 1;
            }
        }

        Queue <GridPos> connectedQueue = new Queue <GridPos>();

        foreach (GridPos coreGP in coreGPs)
        {
            connectedMatrix[coreGP.z, coreGP.x] = 2;
            connectedQueue.Enqueue(coreGP);
        }

        void connectPos(int z, int x)
        {
            if (x < 0 || x >= mechaComponentMatrix.GetLength(1) || z < 0 || z >= mechaComponentMatrix.GetLength(0))
            {
                return;
            }
            else
            {
                int a = connectedMatrix[z, x];
                if (connectedMatrix[z, x] == 1)
                {
                    connectedQueue.Enqueue(new GridPos(x, z));
                    connectedMatrix[z, x] = 2;
                }
            }
        }

        while (connectedQueue.Count > 0)
        {
            GridPos gp = connectedQueue.Dequeue();
            connectPos(gp.z + 1, gp.x);
            connectPos(gp.z - 1, gp.x);
            connectPos(gp.z, gp.x - 1);
            connectPos(gp.z, gp.x + 1);
        }

        for (int z = 0; z < connectedMatrix.GetLength(0); z++)
        {
            for (int x = 0; x < connectedMatrix.GetLength(1); x++)
            {
                if (connectedMatrix[z, x] == 1)
                {
                    isolatedGridPositions.Add((new GridPos(x, z)));
                    MechaComponentBase isolatedComponent = mechaComponentMatrix[z, x];
                    if (!isolatedComponents.Contains(isolatedComponent))
                    {
                        isolatedComponents.Add(isolatedComponent);
                    }
                }
            }
        }

        foreach (GridPos gp in isolatedGridPositions)
        {
            AddIsolatedComponentIndicator(gp);
        }
    }
コード例 #12
0
    public void AddMechaComponent(MechaComponentInfo mci)
    {
        MechaComponentBase mcb = MechaComponentBase.BaseInitialize(mci, this);

        AddMechaComponent(mcb);
    }
コード例 #13
0
 void Awake()
 {
     MechaComponentBase = GetComponentInParent <MechaComponentBase>();
     HitBoxes           = GetComponentsInChildren <HitBox>().ToList();
 }
コード例 #14
0
    private void CommonDrag()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (!CurrentDrag)
            {
                {
                    // Drag items in bag
                    Ray ray = UIManager.Instance.UICamera.ScreenPointToRay(Input.mousePosition);
                    Physics.Raycast(ray, out RaycastHit hit, 1000f, GameManager.Instance.LayerMask_ComponentHitBox);
                    if (hit.collider)
                    {
                        BagItem bagItem = hit.collider.gameObject.GetComponentInParent <BagItem>();
                        if (bagItem)
                        {
                            CurrentDrag          = bagItem.gameObject.GetComponent <Draggable>();
                            CurrentDrag.IsOnDrag = true;
                        }
                        else
                        {
                            CancelCurrentDrag();
                        }
                    }
                    else
                    {
                        CancelCurrentDrag();
                    }
                }

                //Drag components in scene
                if (!CurrentDrag)
                {
                    Ray ray = GameManager.Instance.MainCamera.ScreenPointToRay(Input.mousePosition);
                    Physics.Raycast(ray, out RaycastHit hit, 1000f, GameManager.Instance.LayerMask_ComponentHitBox);
                    if (hit.collider)
                    {
                        HitBox hitBox = hit.collider.gameObject.GetComponent <HitBox>();
                        if (hitBox)
                        {
                            CurrentDrag_MechaComponentBase = hitBox.ParentHitBoxRoot.MechaComponentBase;
                            CurrentDrag          = CurrentDrag_MechaComponentBase.gameObject.GetComponent <Draggable>();
                            CurrentDrag.IsOnDrag = true;
                        }
                        else
                        {
                            CancelCurrentDrag();
                        }
                    }
                    else
                    {
                        CancelCurrentDrag();
                    }
                }

                // Drag items dropped
                if (!CurrentDrag)
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        Ray ray = GameManager.Instance.MainCamera.ScreenPointToRay(Input.mousePosition);
                        Physics.Raycast(ray, out RaycastHit hit, 1000f, GameManager.Instance.LayerMask_ItemDropped);
                        if (hit.collider)
                        {
                            MechaComponentDropSprite mcds = hit.collider.GetComponentInParent <MechaComponentDropSprite>();
                            if (mcds)
                            {
                                MechaComponentBase mcb = MechaComponentBase.BaseInitialize(mcds.MechaComponentInfo.Clone(), BattleManager.Instance.PlayerMecha);
                                GridPos            gp  = GridPos.GetGridPosByMousePos(BattleManager.Instance.PlayerMecha.transform, Vector3.up, GameManager.GridSize);
                                mcb.SetGridPosition(gp);
                                BattleManager.Instance.PlayerMecha.AddMechaComponent(mcb);
                                CurrentDrag          = mcb.GetComponent <Draggable>();
                                CurrentDrag.IsOnDrag = true;
                                mcds.PoolRecycle();
                            }
                        }
                    }
                }
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            CancelCurrentDrag();
        }
    }