public override void Update()
        {
            base.Update();
            Collider[] colliders = Physics.OverlapSphere(this.gameObject.transform.position, m_SearchRadius, ~(1 << this.gameObject.layer));
            List <EntityController> availableTargets = new List <EntityController>();

            foreach (Collider collider in colliders)
            {
                if (Physics.GetIgnoreLayerCollision(collider.gameObject.layer, this.gameObject.layer))
                {
                    continue;
                }
                EntityController entityController = collider.gameObject.GetComponentInParent <EntityController>();
                if (!entityController)
                {
                    continue;
                }
                if (entityController.Entity.Description.EntityType != EntityType.SpaceShip)
                {
                    continue;
                }
                availableTargets.Add(entityController);
            }
            CommonComponents.EntityController.Target = FindBestTarget(availableTargets);
            if (CommonComponents.EntityController.Target && m_NextState != null)
            {
                EntityStateMachine.SetNextState(m_NextState);
                return;
            }
        }
        public override void Update()
        {
            base.Update();

            if (CommonComponents.TranslationalController == null)
            {
                return;
            }
            if (CommonComponents.EntityController.Target && m_OnTargetFoundState)
            {
                EntityStateMachine.SetNextState(m_OnTargetFoundState);
                return;
            }

            float radius = Mathf.PerlinNoise(Age, m_Seed) * (m_MaxOrbitRadius - m_MinOrbitRadius);

            radius = Mathf.Clamp(radius + m_MinOrbitRadius, m_MinOrbitRadius, m_MaxOrbitRadius);
            if (radius != 0.0f)
            {
                m_OrbitPerSecond = m_OrbitSpeed * CommonComponents.EnemyController.Entity.GetStat("core.modtypes.ship.movementspeed").Current / radius;
                m_Angle         += Time.deltaTime * m_OrbitPerSecond * m_OrbitSpeedMultiplier;
            }

            Vector3 targetPosition = Vector3.forward * radius;

            targetPosition  = Quaternion.Euler(0, m_Angle, 0) * targetPosition;
            targetPosition += CommonComponents.EnemyController.Entity.Description.Parent.EntityController.Head.position;
            CommonComponents.TranslationalController.MoveTowardsPosition(targetPosition);
        }
示例#3
0
        private void FireLogic(EntityStateMachine self)
        {
            var   skill       = self.commonComponents.skillLocator.primary;
            var   inputBank   = self.commonComponents.inputBank;
            bool  fire        = inputBank && inputBank.skill1.down;
            bool  justPressed = inputBank && inputBank.skill1.justPressed;
            bool  isReloading = self.state.ToString() == "EntityStates.Bandit2.Weapon.Reload";
            int   charges     = skill.stock;
            float delay       = getDelay(charges);

            if (charges == 0 || isReloading)
            {
                reloadLock = true;
            }

            if ((charges == skill.maxStock && !isReloading) || justPressed)
            {
                reloadLock = false;
            }

            if (!reloadLock && charges > 0 && fire && fixedAge > delay)
            {
                fixedAge = 0;

                // ignore first shot since it's handled by the game
                if (justPressed)
                {
                    return;
                }

                if (skill.skillNameToken == "BANDIT2_PRIMARY_NAME")
                {
                    self.SetNextState(new FireShotgun2());
                }
                else
                {
                    self.SetNextState(new Bandit2FireRifle());
                }

                skill.DeductStock(1);
            }
        }
 public override void Update()
 {
     base.Update();
     if (CooldownManager.GetCooldown(CommonComponents.EntityController) == 0.0f && CommonComponents.EntityController.Target && m_NextState)
     {
         if (CommonComponents.TranslationalController != null)
         {
             CommonComponents.TranslationalController.StopMove();
         }
         EntityStateMachine.SetNextState(m_NextState);
     }
 }
示例#5
0
        protected override bool Wander()
        {
            if (!CommonComponents.EntityController.Target)
            {
                if (m_NoTargetFoundState)
                {
                    EntityStateMachine.SetNextState(m_NoTargetFoundState);
                }
                return(false);
            }

            Vector3 randomPosition = UnityEngine.Random.insideUnitSphere * MaxMoveRadius;

            randomPosition += CommonComponents.EntityController.Target.Head.position;

            return(CommonComponents.TranslationalController.MoveTowardsPosition(randomPosition));
        }
        public override void Update()
        {
            base.Update();

            bool flag = (CommonComponents.EntityController.Target == m_HasTarget);

            if (flag)
            {
                if (m_NextState)
                {
                    EntityStateMachine.SetNextState(m_NextState);
                }
                else
                {
                    EntityStateMachine.SetNextStateToMain();
                }
            }
        }
示例#7
0
        public override void OnEnter()
        {
            base.OnEnter();

            EntityStateMachine desiredStateMachine = this.outer;

            foreach (EntityStateMachine i in base.gameObject.GetComponents <EntityStateMachine>())
            {
                if (i)
                {
                    if (i.customName == "Body")
                    {
                        desiredStateMachine = i;
                    }
                }
            }

            desiredStateMachine.SetNextState(new StartCharge());
            this.outer.SetNextStateToMain();
        }
示例#8
0
        private void ChestBehavior_ItemDrop(On.RoR2.ChestBehavior.orig_ItemDrop orig, ChestBehavior self)
        {
            if (!NetworkServer.active)
            {
                Debug.LogWarning("[Server] function 'System.Void RoR2.ChestBehavior::ItemDrop()' called on client");
                return;
            }

            var chestName = self.gameObject.name.ToLower();

            if (chestName.StartsWith("lunarchest"))
            {
                orig(self);
                return;
            }

            FieldInfo dropPickup      = self.GetType().GetField("dropPickup", BindingFlags.Instance | BindingFlags.NonPublic);
            var       dropPickupValue = (PickupIndex)dropPickup.GetValue(self);

            if (dropPickupValue != PickupIndex.none)
            {
                if (!DropItems && (chestName.StartsWith("chest") || chestName.StartsWith("goldchest")))
                {
                    var pickupController = gameObject.GetComponent <GenericPickupController>();

                    if (pickupController == null)
                    {
                        pickupController = this.gameObject.AddComponent <GenericPickupController>();
                    }

                    var characterBody = LocalUserManager.GetFirstLocalUser().cachedBody;

                    characterBody.inventory.GiveItem(dropPickupValue.itemIndex, 1);

                    pickupController.GetType().GetMethod("SendPickupMessage", BindingFlags.Static | BindingFlags.NonPublic)
                    .Invoke(pickupController, new object[] { characterBody.inventory.GetComponent <CharacterMaster>(), dropPickupValue });

                    dropPickup.SetValue(self, PickupIndex.none);
                    return;
                }

                orig(self);
                return;
            }

            // Steal opening sound from timed chest without changing to a problematic state
            EntityStateMachine component = self.GetComponent <EntityStateMachine>();

            if (component)
            {
                component.SetNextState(EntityState.Instantiate(new SerializableEntityStateType(typeof(EntityStates.TimedChest.Opening))));
            }

            // Generate list of 3 random item indexes
            var randomItemList = new List <PickupIndex>();

            randomItemList.Add(RollVoteItem(self));
            randomItemList.Add(RollVoteItem(self));
            randomItemList.Add(RollVoteItem(self));

            // Create a new vote, by passing valid poll options and vote duration
            var vote = new Vote(new List <string>(new string[] { "1", "2", "3" }), VoteDuration);

            vote.StartEventHandler += (_, __) =>
            {
                var characterBody = LocalUserManager.GetFirstLocalUser().cachedBody;

                var notificationQueue = characterBody.gameObject.GetComponent <VoteNotificationQueue>();

                if (notificationQueue == null)
                {
                    notificationQueue = characterBody.gameObject.AddComponent <VoteNotificationQueue>();
                }

                notificationQueue.OnVoteStart(randomItemList, VoteDuration);

                // Notify the event in chat
                SendChatMessage(
                    string.Format("Vote for the next item! (1) {0} | (2) {1} | (3) {2}",
                                  Language.GetString(randomItemList[0].GetPickupNameToken()),
                                  Language.GetString(randomItemList[1].GetPickupNameToken()),
                                  Language.GetString(randomItemList[2].GetPickupNameToken())
                                  )
                    );
            };

            vote.EndEventHandler += (_, e) =>
            {
                var votedItemName = Language.GetString(randomItemList[e.VotedIndex].GetPickupNameToken());

                float totalVotesCount = 1f;
                int   winnerCount     = 1;

                if (e.VoteCounter.Keys.Count > 0)
                {
                    totalVotesCount = e.VoteCounter.Sum(el => el.Value);
                    winnerCount     = e.VoteCounter[(e.VotedIndex + 1).ToString()];
                }

                SendChatMessage(
                    string.Format(
                        "({0}) {1} won! ({2})",
                        e.VotedIndex + 1,
                        votedItemName,
                        (winnerCount / totalVotesCount).ToString("P1", CultureInfo.InvariantCulture).Replace(" %", "%")
                        )
                    );

                var votedItem = randomItemList[e.VotedIndex];

                dropPickup.SetValue(self, votedItem);
                self.Open();
            };

            VoteManager.AddVote(vote);
        }
示例#9
0
        public override void OnEnter()
        {
            base.OnEnter();
            base.characterBody.isSprinting = true;
            if (base.cameraTargetParams)
            {
                base.cameraTargetParams.aimMode = CameraTargetParams.AimType.Standard;
            }
            base.characterBody.hideCrosshair = false;

            EntityStateMachine desiredStateMachine = this.outer;

            foreach (EntityStateMachine i in base.gameObject.GetComponents <EntityStateMachine>())
            {
                if (i)
                {
                    if (i.customName == "Weapon")
                    {
                        desiredStateMachine = i;
                    }
                }
            }

            if (!this.tracker.GetTrackingTarget())
            {
                if (this.isGrounded)
                {
                    Uppercut nextState = new Uppercut
                    {
                        charge = this.charge
                    };
                    desiredStateMachine.SetNextState(nextState);
                    this.outer.SetNextStateToMain();
                    return;
                }
                else
                {
                    Downslash nextState = new Downslash
                    {
                        charge = this.charge
                    };
                    desiredStateMachine.SetNextState(nextState);
                    this.outer.SetNextStateToMain();
                    return;
                }
            }

            float desiredDist = 10f;

            if (!this.isGrounded)
            {
                desiredDist = 7f;
            }

            float dist = Vector3.Distance(base.transform.position, this.tracker.GetTrackingTarget().transform.position);

            if (dist <= desiredDist)
            {
                if (this.isGrounded)
                {
                    Uppercut nextState = new Uppercut
                    {
                        charge = this.charge
                    };
                    desiredStateMachine.SetNextState(nextState);
                    this.outer.SetNextStateToMain();
                    return;
                }
                else
                {
                    Downslash nextState = new Downslash
                    {
                        charge = this.charge
                    };
                    desiredStateMachine.SetNextState(nextState);
                    this.outer.SetNextStateToMain();
                    return;
                }
            }
            else
            {
                Lunge nextState = new Lunge
                {
                    charge = this.charge
                };
                desiredStateMachine.SetNextState(nextState);
                this.outer.SetNextStateToMain();
                return;
            }
        }