public void SetEnemy(CombatCharacter player)
        {
            player = GeneralMethods.CopyObject(player);

            Player                   = player;
            Character                = Player;
            Player.CharacterMono     = this;
            Controller.SpawnPosition = transform.position;
            Controller.State         = RPGControllerState.Idle;
            Player.VitalHandler      = new VitalHandler(Player);
            Player.VitalHandler.Health.CurrentValue = Player.VitalHandler.Health.MaxValue;
            Player.CCInit();
            RefreshPrefabs();
            Name        = Character.Name;
            Initialised = true;
        }
Пример #2
0
        public static GameObject SpawnPet(PetData data, Vector3 position)
        {
            var pet = data;

            if (pet != null)
            {
                CombatCharacter petChar = null;
                if (pet.IsNpc)
                {
                    var npc = Rm_RPGHandler.Instance.Repositories.Interactable.GetNPC(pet.CharacterID);
                    petChar = GeneralMethods.CopyObject((CombatCharacter)npc);
                }
                else
                {
                    var enemy = Rm_RPGHandler.Instance.Repositories.Enemies.Get(pet.CharacterID);
                    petChar = GeneralMethods.CopyObject(enemy);
                }

                if (GetObject.PlayerCharacter.CurrentPet != null)
                {
                    GetObject.PlayerCharacter.CurrentPet.Remove();
                }

                var petGo   = (GameObject)Instantiate(Resources.Load(petChar.CharPrefabPath), position + Vector3.back, Quaternion.identity);
                var petMono = petGo.AddComponent <PetMono>();
                var follow  = petGo.GetComponent <RPGFollow>();
                follow.FollowTarget   = true;
                follow.TargetToFollow = GetObject.PlayerMono;
                petMono.PetData       = data;

                //Update current pet
                GetObject.PlayerCharacter.CurrentPet = petMono;
                GetObject.PlayerSave.CurrentPet      = data;
                return(petGo);
            }

            return(null);
        }
        //todo: rethink these, we should add skill or talent, so we can first check if we are immune/susceptible to it
        //in which case we can pre-multiply the damage or just not apply the skill and return "Immune"

        public bool IsFriendly(BaseCharacter target)
        {
            if (target == null)
            {
                return(true);
            }

            //pet can't be attacked if it's idle only
            var targetIsPet = target.CharacterMono.GetComponent <PetMono>();

            if (targetIsPet != null && targetIsPet.PetData.CurrentBehaviour == PetBehaviour.PetOnly)
            {
                return(true);
            }

            //pet can't attack player
            if (CharacterMono == null)
            {
                return(true);
            }

            var iAmPet = CharacterMono.GetComponent <PetMono>();

            if (iAmPet != null && target is PlayerCharacter)
            {
                return(true);
            }

            if (iAmPet)
            {
                return(GetObject.PlayerCharacter.IsFriendly(target));
            }

            if (targetIsPet)
            {
                return(IsFriendly(GetObject.PlayerCharacter));
            }

            var allReps     = Rm_RPGHandler.Instance.Repositories.Quests.AllReputations;
            var players     = new PlayerCharacter[2];
            var combatChars = new CombatCharacter[2];

            switch (CharacterType)
            {
            case CharacterType.Player:
                players[0] = (PlayerCharacter)this;
                break;

            case CharacterType.NPC:
            case CharacterType.Enemy:
                combatChars[0] = (CombatCharacter)this;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            switch (target.CharacterType)
            {
            case CharacterType.Player:
                players[players[0] == null ? 0 : 1] = (PlayerCharacter)target;
                break;

            case CharacterType.NPC:
            case CharacterType.Enemy:
                combatChars[combatChars[0] == null ? 0 : 1] = (CombatCharacter)target;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (players.Count(p => p != null) == 2)
            {
                return(true);
            }
            else if (players.Count(p => p != null) == 1 && combatChars.Count(p => p != null) == 1)
            {
                var targetChar   = combatChars[0];
                var rep          = allReps.FirstOrDefault(r => r.ID == targetChar.ReputationId);
                var playerRepVal = GetObject.PlayerSave.QuestLog.AllReputations.FirstOrDefault(r => r.ReputationID == targetChar.ReputationId);
                if (rep != null && playerRepVal != null)
                {
                    return(!rep.AttackIfBelowReputation || playerRepVal.Value >= rep.BelowReputationValue);
                }
                else
                {
                    Debug.LogError("Could not find reputation for  " + targetChar.Name + "[ RepId: " + targetChar.ReputationId + "]");
                }
            }
            else
            {
                var myrep    = allReps.FirstOrDefault(r => r.ID == combatChars[0].ReputationId);
                var enemyrep = allReps.FirstOrDefault(r => r.ID == combatChars[1].ReputationId);


                if (myrep == enemyrep)
                {
                    return(true);
                }

                //EE
                if (myrep.EnemyFactions.First(e => e.ID == enemyrep.ID).IsTrue&&
                    enemyrep.EnemyFactions.First(e => e.ID == myrep.ID).IsTrue)
                {
                    return(false);
                }
                else if (myrep.EnemyFactions.First(e => e.ID == enemyrep.ID).IsTrue || enemyrep.EnemyFactions.First(e => e.ID == myrep.ID).IsTrue)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            return(true);
        }