コード例 #1
0
        /// <summary>
        /// If in Charging state, will either stop charging or fire depending on Data
        /// </summary>
        public void TriggerRelease()
        {
            if (State == PFState.Charging)
            {
                //Interupt charging
                StopCoroutine(chargeCoroutine);
                ChargeUpTimer = 0f;

                if (OnTriggerReleased != null)
                {
                    OnTriggerReleased.Invoke(this);
                }

                if (pfData.ChargeTime.requireFullyCharged == false)
                {
                    //Fire
                    Fire();
                }
                else
                {
                    //Cancel
                    State = PFState.Ready;

                    if (OnChargeCancelled != null)
                    {
                        OnChargeCancelled.Invoke(this);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Prevents the PF for firing. Used to control rate of fire and forced reloading
        /// </summary>
        /// <param name="waitTime"></param>
        /// <returns></returns>
        private IEnumerator CoolDown()
        {
            CoolDownTimer = pfData.RateOfFire.GetWaitTime(CurrentAmmo);

            while (CoolDownTimer > 0f)
            {
                if (OnCoolDown != null)
                {
                    OnCoolDown.Invoke(this, CoolDownTimer);
                }

                CoolDownTimer -= Time.deltaTime;

                yield return(null);
            }

            CoolDownTimer = 0f;

            //If was a forced reload
            if (CurrentAmmo <= 0)
            {
                CurrentAmmo = pfData.RateOfFire.AmmoCapacity;
            }

            if (OnCoolDownComplete != null)
            {
                OnCoolDownComplete.Invoke(this);
            }

            State = PFState.Ready;
        }
コード例 #3
0
ファイル: PathFind.cs プロジェクト: FluentZap/devilguard
 public void Clear_All()
 {
     Found_State = PFState.NotFinished;
     Path.Clear();
     Priority_List.List.Clear();
     List.Clear();
     CloseList.Clear();
 }
コード例 #4
0
        private IEnumerator ManualReload_CO()
        {
            yield return(new WaitForSeconds(pfData.RateOfFire.ReloadTime));

            //for now, we are assuming the Overwatch model of ammo - infinte with reloads
            CurrentAmmo = pfData.RateOfFire.AmmoCapacity;
            State       = PFState.Ready;
        }
コード例 #5
0
 void Start()
 {
     width        = groundTilemap.cellBounds.size.x;
     height       = groundTilemap.cellBounds.size.y;
     pathFinding  = new PathFinding(width, height, cellSize, groundTilemap);
     currentState = PFState.SET_START;
     SetObstacle();
 }
コード例 #6
0
ファイル: PFState.cs プロジェクト: EMonk72/EMonk
        /// <summary>Get cost of moving to this node from the supplied other node</summary>
        /// <typeparam name="T">Content type of other node, must derive from IMapNode</typeparam>
        /// <param name="from">Other node to move from</param>
        /// <returns>Total cost of movement, or +Infinity on invalid move</returns>
        public double CalcMoveCost <T>(PFState <T> from)
            where T : class, IMapNode, new()
        {
            if (!from.Visited)
            {
                return(double.PositiveInfinity);
            }
            MapDirection dir  = DirectionFrom(from);
            double       mult = dir.IsOrthogonal() ? 1 : 1.5;

            return(from.TotalCost + MoveCost * mult);
        }
コード例 #7
0
        /// <summary>
        /// If ManualReload, will switch back to ready
        /// </summary>
        public void CancelManualReload()
        {
            if (State == PFState.ManualReload)
            {
                StopCoroutine(manaualReloadCoroutine);
                State = PFState.Ready;

                if (OnManualReload != null)
                {
                    OnManualReload.Invoke(this);
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// When in Ready state, will begin charging the weapon. NB if chargeTime is 0, will immediately call fire
        /// </summary>
        public void TriggerPress()
        {
            if (State == PFState.Ready)
            {
                State           = PFState.Charging;
                chargeCoroutine = StartCoroutine(Charge());

                if (OnTriggerPressed != null)
                {
                    OnTriggerPressed.Invoke(this);
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// If in Ready or Charging, will begin a manual reload
        /// </summary>
        public void ManualReload()
        {
            if (State == PFState.Ready || State == PFState.Charging)
            {
                if (chargeCoroutine != null)
                {
                    StopCoroutine(chargeCoroutine);
                }

                State = PFState.ManualReload;
                manaualReloadCoroutine = StartCoroutine(ManualReload_CO());

                if (OnManualReload != null)
                {
                    OnManualReload.Invoke(this);
                }
            }
        }
コード例 #10
0
ファイル: PathFind.cs プロジェクト: FluentZap/devilguard
        public void Standard_Pathfind(Point start_Point, Point end_Point, int MaxDistance)
        {
            if (Math.Abs(start_Point.X - end_Point.X) > MaxDistance || Math.Abs(start_Point.Y - end_Point.Y) > MaxDistance)
            {
                Found_State = PFState.Imposable; return;
            }

            Clear_All();
            MapRect = new Rectangle(start_Point, new Point(0, 0));
            MapRect.Inflate(MaxDistance, MaxDistance);
            if (MapRect.X < 0)
            {
                MapRect.X = 0;
            }
            if (MapRect.X > 999)
            {
                MapRect.X = 999;
            }

            if (MapRect.Y < 0)
            {
                MapRect.Y = 0;
            }
            if (MapRect.Y > 999)
            {
                MapRect.Y = 999;
            }

            AddTo_OpenList(new Node(start_Point, null, 10, 0));
            Start_Point = start_Point;
            End_Point   = end_Point;

            if (Tile_Map[End_Point.X, End_Point.Y].Structure != null)
            {
                if (!(Data.structure.Data[Tile_Map[End_Point.X, End_Point.Y].Structure.Type].Walkalble))
                {
                    Found_State = PFState.Imposable; return;
                }
            }
            do
            {
                Pathfind_Step();
            }while (Found_State == PFState.NotFinished);
        }
コード例 #11
0
    // Update is called once per frame
    void Update()
    {
        UpdateObstacleTiles();

        if (Input.GetMouseButtonDown(0))
        {
            switch (currentState)
            {
            case PFState.SET_START:
                GetMouseWorldPosition(out startX, out startY);
                if (startX >= 0 && startY >= 0 && startX < pathFinding.GetGrid().GetWidth() && startY < pathFinding.GetGrid().GetHeight())
                {
                    currentState = PFState.SET_END;
                }
                break;

            case PFState.SET_END:
                GetMouseWorldPosition(out endX, out endY);
                if (endX >= 0 && endY >= 0 && endX < pathFinding.GetGrid().GetWidth() && endY < pathFinding.GetGrid().GetHeight())
                {
                    currentState = PFState.FIND_PATH;
                }
                break;

            default:
                break;
            }

            if (currentState == PFState.FIND_PATH)
            {
                path         = pathFinding.FindPath(startX, startY, endX, endY);
                currentState = PFState.SET_START;
            }

            if (path != null)
            {
                for (int i = 0; i < path.Count - 1; i++)
                {
                    Debug.DrawLine(new Vector3(path[i].x, path[i].y) * cellSize + Vector3.one * (cellSize / 2) + path[i].grid.originPosition,
                                   new Vector3(path[i + 1].x, path[i + 1].y) * cellSize + Vector3.one * (cellSize / 2) + path[i].grid.originPosition, Color.green, 100f);
                }
            }
        }
    }
コード例 #12
0
        /*
         * public void ResumeCoolDown()
         * {
         *  if (State == PFState.CoolDownInterupt)
         *  {
         *      State = PFState.CoolDown;
         *      coolDownCoroutine = StartCoroutine(CoolDown());
         *  }
         * }
         *
         * public void InteruptCoolDown()
         * {
         *  if (State == PFState.CoolDown)
         *  {
         *      State = PFState.CoolDownInterupt;
         *      StopCoroutine(coolDownCoroutine);
         *  }
         * }
         */
        #endregion

        #region Private Weapon Methods
        /// <summary>
        /// Launches projectile(s) and transistions into cool down
        /// </summary>
        private void Fire()
        {
            if (projectilePrefab == null)
            {
                Debug.LogWarning("ParametricFirearm: Unable to fire as projectile prefab is null");
                return;
            }

            for (int i = 0; i < pfData.Multishot.numberOfShots; i++)
            {
                //Spawn the projectile
                var projectile = Instantiate(projectilePrefab);

                if (barrelTip != null)
                {
                    projectile.transform.position = barrelTip.position;
                    projectile.transform.forward  = barrelTip.forward;
                }

                //Clone projectile data
                projectile.Launch(this.Agent, this, Instantiate(pfData.Projectile));

                //Controlling ROF
                //CUrrent ammo is decremented before being sent to GetWaitTime to avoid the off by one error
                CurrentAmmo--;

                //Run out of ammo - will force reload
                if (CurrentAmmo <= 0)
                {
                    break;
                }
            }

            if (OnFire != null)
            {
                OnFire.Invoke(this);
            }

            State             = PFState.CoolDown;
            coolDownCoroutine = StartCoroutine(CoolDown());
        }
コード例 #13
0
ファイル: PathFind.cs プロジェクト: FluentZap/devilguard
        public PFState Pathfind_Step()
        {
            if (Priority_List.Count() == 0)
            {
                Found_State = PFState.Imposable;
            }
            if (Found_State != PFState.NotFinished)
            {
                return(Found_State);
            }

            if (Found_State == PFState.NotFinished)
            {
                int  MinF = Priority_List.MinList();
                Node Node = List[Priority_List.FirstNode(MinF)];
                if (Node.Pos == End_Point)
                {
                    Found_State = PFState.Found;
                }
                Priority_List.Remove(MinF, Node.Pos);
                Calculate_Node(Node);
                CloseList.Add(Node.Pos);

                //Add items to found Node
                if (Found_State == PFState.Found)
                {
                    Node ListNode = List[End_Point];
                    int  index;
                    while (ListNode != null)
                    {
                        Path.Add(ListNode.Pos);
                        ListNode = ListNode.Parent;
                    }
                    Path.Reverse();
                }
                return(PFState.NotFinished);
            }
            return(PFState.NotFinished);
        }
コード例 #14
0
 public void OnClickPath(bool toggled)
 {
     state = PFState.PATH;
 }
コード例 #15
0
 public void OnClickPaint4(bool toggled)
 {
     state     = PFState.PAINT;
     paintMask = 4;
 }