Esempio n. 1
0
        public override IEnumerator Routine(NodeChain nodeChain)
        {
            var gameObject       = (GameObject)ValueOf("GameObject");
            var targetPos        = (RPGVector3)ValueOf("Target Position");
            var moveSpeed        = (float)ValueOf("Move Speed");
            var waitToFinish     = (bool)ValueOf("Wait to finish?");
            var runInsteadOfWalk = (bool)ValueOf("Run Instead of Walk?");

            var control = gameObject.GetComponent <RPGController>();
            var queue   = new RPGActionQueue();

            var originalAiSetting = control.ControlledByAI;

            var moveAnim = runInsteadOfWalk ? control.Character.LegacyAnimations.RunAnim : control.Character.LegacyAnimations.WalkAnim;

            queue.Add(RPGActionFactory.MoveToPosition(targetPos, 1, moveSpeed).WithAnimation(moveAnim));
            queue.Add(RPGActionFactory.WaitForSeconds(0.1f));
            queue.Add(RPGActionFactory.PlayAnimation(control.Character.LegacyAnimations.IdleAnim));
            queue.Add(RPGActionFactory.BasicJump(0));

            control.ForceStopHandlingActions();
            control.BeginActionQueue(queue);


            if (waitToFinish)
            {
                while (Vector3.Distance(control.transform.position, targetPos) > 2.5f)
                {
                    yield return(null);
                }
            }

            yield return(null);
        }
        protected override void Eval(NodeChain nodeChain)
        {
            var itemId   = (string)ValueOf("Item");
            var quantity = (int)ValueOf("Quantity");
            var item     = Rm_RPGHandler.Instance.Repositories.QuestItems.Get(itemId);

            if (item != null)
            {
                var spawnPos = (RPGVector3)ValueOf("Position");

                var stackable = item as IStackable;
                if (stackable != null)
                {
                    stackable.CurrentStacks = quantity;
                    LootSpawner.Instance.SpawnItem(spawnPos, item);
                }
                else
                {
                    for (int i = 0; i < quantity; i++)
                    {
                        LootSpawner.Instance.SpawnItem(spawnPos + new RPGVector3(0, 0.2f * i, 0), Rm_RPGHandler.Instance.Repositories.QuestItems.Get(itemId));
                    }
                }
            }
        }
        protected override void Eval(NodeChain nodeChain)
        {
            var gameObject   = (GameObject)ValueOf("GameObject");
            var destroyAfter = (float)ValueOf("Destroy After");

            Object.Destroy(gameObject, destroyAfter);
        }
Esempio n. 4
0
        public override IEnumerator Routine(NodeChain nodeChain)
        {
            var gameObject      = (GameObject)ValueOf("GameObject");
            var animationToPlay = (string)ValueOf("Animation Name");
            var timeToPlay      = Convert.ToSingle(ValueOf("Play Time"));

            var anim = gameObject.GetComponent <Animation>();

            var rpgController = gameObject.GetComponent <RPGController>();

            if (rpgController != null)
            {
                anim = rpgController.Animation;
                anim.CrossFade(animationToPlay);
            }
            else
            {
                gameObject.GetComponent <Animation>().CrossFade(animationToPlay);
            }

            if (anim == null)
            {
                throw new NodeParameterMissingException("Animation component not found on gameobject");
            }

            yield return(new WaitForSeconds(timeToPlay));
        }
Esempio n. 5
0
        public override object EvaluateInput(NodeChain nodeChain, Func <object, object> func)
        {
            var property = GetObject.PlayerMonoGameObject;
            var result   = func(property);

            return(result);
        }
        public override object EvaluateInput(NodeChain nodeChain, Func <object, object> func)
        {
            var property = DialogHandler.Instance.DialogNpc.gameObject;
            var result   = func(property);

            return(result);
        }
        public override IEnumerator Routine(NodeChain nodeChain)
        {
            var soundClipPath = (string)ValueOf("Sound");
            var soundClip     = Resources.Load(soundClipPath) as AudioClip;

            var usePlayOnceId = (bool)ValueOf("Use Play Once ID?");
            var playOnceId    = usePlayOnceId ? (string)Parameter("Use Play Once ID?").ValueOf("ID") : "";

            var useDuration = (bool)ValueOf("With Duration?");
            var duration    = useDuration ? (float)Parameter("With Duration?").ValueOf("Duration") : -1f;

            var waitToFinish = (bool)ValueOf("Wait to finish?");

            AudioPlayer.Instance.Play(soundClip, AudioType.SoundFX, Vector3.zero, null, playOnceId, duration);

            if (waitToFinish)
            {
                if (useDuration)
                {
                    yield return(new WaitForSeconds(duration));
                }
                else
                {
                    yield return(new WaitForSeconds(soundClip.length));
                }
            }

            yield return(null);
        }
        protected override bool Eval(NodeChain nodeChain)
        {
            var combatant    = ValueOf("Combatant") as BaseCharacter ?? ((GameObject)ValueOf("Combatant")).GetComponent <BaseCharacterMono>().Character;
            var auraEffectID = (string)ValueOf("Aura");

            return(combatant.AuraEffects.FirstOrDefault(s => s.SkillId == auraEffectID) != null);
        }
Esempio n. 9
0
        public void Init()
        {
            var achievementsNodeBank = Rm_RPGHandler.Instance.Nodes.AchievementsNodeBank;

            foreach (var achievementTree in achievementsNodeBank.NodeTrees)
            {
                var achievementInfoNode = achievementTree.Nodes.FirstOrDefault(n => n is AchievementStartNode);
                var id          = achievementTree.ID;
                var name        = (string)achievementInfoNode.ValueOf("Name");
                var description = (string)achievementInfoNode.ValueOf("Description");
                var spritePath  = (string)achievementInfoNode.ValueOf("Image");
                var hasProgress = (bool)achievementInfoNode.ValueOf("Has Progress?");
                var achievement = new Achievement(id, name, spritePath, description, 1)
                {
                    HasProgress = hasProgress
                };
                if (achievement.HasProgress)
                {
                    var nodeTree         = Rm_RPGHandler.Instance.Nodes.AchievementsNodeBank.NodeTrees.FirstOrDefault(n => n.ID == achievement.ID);
                    var maxProgressChain = new NodeChain(nodeTree, typeof(AchievementMaxProgress));
                    while (!maxProgressChain.Done)
                    {
                        maxProgressChain.Evaluate();
                    }

                    achievement.Progress.TargetValue = maxProgressChain.IntValue;
                }

                Achievements.Add(achievement);
            }
        }
Esempio n. 10
0
        protected override int Eval(NodeChain nodeChain)
        {
            var questID = (string)ValueOf("Quest");
            var quest   = GetObject.PlayerSave.QuestLog.AllObjectives.FirstOrDefault(q => q.ID == questID);

            if (quest != null)
            {
                if (!quest.IsAccepted && !quest.TurnedIn) //startable
                {
                    return(0);
                }
                else if (!quest.ConditionsMet && quest.IsAccepted && !quest.TurnedIn) //inprogress
                {
                    return(1);
                }
                else if (quest.ConditionsMet && quest.IsAccepted && !quest.TurnedIn) //completable
                {
                    return(2);
                }
                else if (quest.TurnedIn) //completed
                {
                    return(3);
                }
                else //notfound
                {
                    return(4);
                }
            }

            return(4);
        }
        protected override void Eval(NodeChain nodeChain)
        {
            var damage    = (int)ValueOf("Damage");
            var element   = (string)ValueOf("Elemental Name");
            var combatant = ValueOf("Combatant") as BaseCharacter ?? ((GameObject)ValueOf("Combatant")).GetComponent <BaseCharacterMono>().Character;


            var elementalId = RPG.Combat.GetElementalIdByName(element);

            if (!string.IsNullOrEmpty(elementalId))
            {
                if (combatant != null)
                {
                    var damageToDeal = new Damage()
                    {
                        MinDamage = damage,
                        MaxDamage = damage
                    };

                    damageToDeal.ElementalDamages.First(e => e.ElementID == elementalId).MinDamage = damage;
                    damageToDeal.ElementalDamages.First(e => e.ElementID == elementalId).MaxDamage = damage;

                    combatant.VitalHandler.TakeDamage(null, damageToDeal, false);
                }
            }
            else
            {
                Debug.LogError("[RPGAIO] Deal elemental damage node did not find element named: " + element);
            }
        }
Esempio n. 12
0
        private IEnumerator StartRoutine(NodeChain nodeChain)
        {
            _isDone = false;
            yield return(GetObject.EventHandler.StartCoroutine(Routine(nodeChain)));

            _isDone = true;
        }
        protected override void Eval(NodeChain nodeChain)
        {
            var traitId = (string)ValueOf("Trait");
            var amount  = Convert.ToInt32(ValueOf("Amount"));

            GetObject.PlayerCharacter.AddTraitExp(traitId, amount);
        }
        protected override void Eval(NodeChain nodeChain)
        {
            var itemId   = (string)ValueOf("Item");
            var quantity = (int)ValueOf("Quantity");

            var playerInventory = GetObject.PlayerCharacter.Inventory;

            if (quantity == 1)
            {
                var item = playerInventory.GetAllItems().FirstOrDefault(i => i.ID == itemId);
                if (item != null)
                {
                    var stackable = item as IStackable;
                    if (stackable != null)
                    {
                        playerInventory.RemoveStack(item, quantity);
                    }
                    else
                    {
                        playerInventory.RemoveItem(itemId);
                    }
                }
                else
                {
                    Debug.LogWarning("[RPGAIO] Node event tried to remove item from player inventory but it was not found.");
                }
            }
            else
            {
                var allItems = playerInventory.GetAllItems();
                var item     = allItems.FirstOrDefault(i => i.ID == itemId);

                if (item != null)
                {
                    var stackable = item as IStackable;
                    if (stackable != null)
                    {
                        playerInventory.RemoveStack(item, quantity);
                    }
                    else
                    {
                        var amountFound = allItems.Count(i => i.ID == itemId);
                        if (amountFound < quantity)
                        {
                            Debug.LogWarning("[RPGAIO] Node event did not find enough quantity of an item to remove, but will remove as many as possible.");
                        }
                        var amountToRemove = Mathf.Min(quantity, amountFound);
                        for (int i = 0; i < amountToRemove; i++)
                        {
                            playerInventory.RemoveItem(itemId);
                        }
                    }
                }
                else
                {
                    Debug.LogWarning("[RPGAIO] Node event tried to remove item from player inventory but it was not found.");
                }
            }
        }
        protected override void Eval(NodeChain nodeChain)
        {
            var gameObjectToCall = (GameObject)ValueOf("Target GameObject");
            var componentName    = (string)ValueOf("Component Name");
            var functionName     = (string)ValueOf("Function Name");
            var requireReciever  = (bool)ValueOf("Require Reciever") ? SendMessageOptions.RequireReceiver : SendMessageOptions.DontRequireReceiver;

            var arguments = new List <object>();

            for (int i = 1; i <= 5; i++)
            {
                var paramName = "UseParam" + i.ToString();
                var useParam  = (bool)ValueOf(paramName);
                if (useParam)
                {
                    var selectedParamType = (int)Parameter(paramName).ValueOf("ParamType");
                    switch (selectedParamType)
                    {
                    case 0:
                        var stringParam = (string)Parameter(paramName).SubParam("ParamType").Parameter.ValueOf("String Param");
                        arguments.Add(stringParam);
                        break;

                    case 1:
                        var boolParam = (bool)Parameter(paramName).SubParam("ParamType").Parameter.ValueOf("Bool Param");
                        arguments.Add(boolParam);
                        break;

                    case 2:
                        var intParam = (int)Parameter(paramName).SubParam("ParamType").Parameter.ValueOf("Int Param");
                        arguments.Add(intParam);
                        break;

                    case 3:
                        var floatParam = (float)Parameter(paramName).SubParam("ParamType").Parameter.ValueOf("Float Param");
                        arguments.Add(floatParam);
                        break;

                    case 4:
                        var gameObjParam = (GameObject)Parameter(paramName).SubParam("ParamType").Parameter.ValueOf("GameObject Param");
                        arguments.Add(gameObjParam);
                        break;
                    }
                }
            }

            if (arguments.Count == 0)
            {
                gameObjectToCall.GetComponent(componentName).SendMessage(functionName, requireReciever);
            }
            else if (arguments.Count == 1)
            {
                gameObjectToCall.GetComponent(componentName).SendMessage(functionName, arguments[0], requireReciever);
            }
            else
            {
                gameObjectToCall.GetComponent(componentName).SendMessage(functionName, arguments.ToArray(), requireReciever);
            }
        }
Esempio n. 16
0
 public void SetNodeChain(NodeChain nodeChain)
 {
     NodeChain = nodeChain;
     foreach (var val in SubParams.Values)
     {
         val.SetNodeChain(nodeChain);
     }
 }
        public EventContainer RunNodeChain(NodeChain nodeChainToRun)
        {
            var newEvent = new EventContainer(nodeChainToRun);

            _currentEvents.Add(newEvent);
            StartCoroutine(HandleEvent(newEvent));
            return(newEvent);
        }
        protected override bool Eval(NodeChain nodeChain)
        {
            var combatant = (CombatCharacter)ValueOf("Enemy");
            var monsterId = combatant.MonsterTypeID;
            var compareId = (string)ValueOf("Type");

            return(monsterId == compareId);
        }
        protected override bool Eval(NodeChain nodeChain)
        {
            var combatant = GetObject.PlayerCharacter;
            var weaponId  = (string)ValueOf("Weapon Type");
            var offhand   = combatant.Equipment.EquippedOffHand != null ? combatant.Equipment.EquippedOffHand as Weapon : null;

            return(offhand != null && offhand.WeaponTypeID == weaponId);
        }
        protected override void Eval(NodeChain nodeChain)
        {
            var player     = GetObject.PlayerCharacter;
            var reputation = (string)ValueOf("Reputation");
            var amount     = Convert.ToInt32(ValueOf("Amount"));

            player.AddReputation(reputation, amount);
        }
        public override object EvaluateInput(NodeChain nodeChain, Func <object, object> func)
        {
            var variable = nodeChain.DamageDealt.Physical;
            var result   = Convert.ToInt32(func(variable));

            nodeChain.DamageDealt.Physical = result;
            return(result);
        }
        protected override void Eval(NodeChain nodeChain)
        {
            var vendorShop = (string)ValueOf("Vendor Shop");

            RPG.Events.OnOpenVendor(new RPGEvents.OpenVendorEventArgs()
            {
                VendorShop = vendorShop
            });
        }
Esempio n. 23
0
 protected override void Eval(NodeChain nodeChain)
 {
     ApplyFunctionTo("Attr", o =>
     {
         var val = Convert.ToSingle(o);
         Debug.Log("[" + (string)ValueOf("Identifier") + "]:" + val);
         return(val);
     });
 }
Esempio n. 24
0
        protected override void Eval(NodeChain nodeChain)
        {
            var player = GetObject.PlayerCharacter;

            if (player.CurrentPet != null)
            {
                player.CurrentPet.Remove();
            }
        }
Esempio n. 25
0
        protected override bool Eval(NodeChain nodeChain)
        {
            var combatant = ValueOf("Combatant") as BaseCharacter ?? ((GameObject)ValueOf("Combatant")).GetComponent <BaseCharacterMono>().Character;

            var isMelee = (bool)ValueOf("Melee?");

            return((isMelee && combatant.AttackStyle == AttackStyle.Melee) ||
                   (!isMelee && combatant.AttackStyle == AttackStyle.Ranged));
        }
Esempio n. 26
0
        public override IEnumerator Routine(NodeChain nodeChain)
        {
            var subtitleUI = GetObject.UIHandler.SubtitleUI;

            while (subtitleUI.IsShowingSubtitles)
            {
                yield return(null);
            }
        }
        protected override void Eval(NodeChain nodeChain)
        {
            var value = Convert.ToSingle(ValueOf("Value"));

            ApplyFunctionTo("Float", o =>
            {
                o = value;
                return(o);
            });
        }
Esempio n. 28
0
        public override object EvaluateInput(NodeChain nodeChain, Func <object, object> func)
        {
            if (func != null)
            {
                var result = func(nodeChain.BoolValue);
                nodeChain.BoolValue = (bool)result;
            }

            return(nodeChain.BoolValue);
        }
Esempio n. 29
0
        protected override void Eval(NodeChain nodeChain)
        {
            var value = Convert.ToInt32(ValueOf("Value"));

            ApplyFunctionTo("Integer", o =>
            {
                o = value;
                return(o);
            });
        }
Esempio n. 30
0
        protected override void Eval(NodeChain nodeChain)
        {
            RPG.Events.OnOpenCrafting(new RPGEvents.OpenCraftingEventArgs());
            var closeIfPlayerMoves = (bool)ValueOf("Close If Player Moves");

            if (closeIfPlayerMoves)
            {
                GetObject.UIHandler.CraftingUI.OpenedByDialog = true;
            }
        }