Exemple #1
0
            public void Show()
            {
                DungeonObjectEvent e = transform.GetComponent <DungeonObjectEvent>();

                if (e != null)
                {
                    e.Show();
                }
            }
Exemple #2
0
        // -------------------------------------------------------------------------------
        // CreateDungeonObject
        // -------------------------------------------------------------------------------
        private void CreateDungeonObject(int x, int y, DungeonTileEvent tile)
        {
            if (tile != null)
            {
                GameObject instance = (GameObject)GameObject.Instantiate(tile.objectPrefab);

                if (Vector3Helper.CardinalDirection(tile.facingDirection) != Vector3.zero)
                {
                    instance.transform.forward = Vector3Helper.CardinalDirection(tile.facingDirection);
                }

                instance.transform.position = new Vector3(x, tile.offsetHeight, y);

                if (tile.facingDirection != DirectionType.None && !tile.interactFromBothSides)
                {
                    instance.transform.position -= instance.transform.forward / 3;
                }

                instance.transform.parent = MapContainer;
                instance.name             = string.Format("{0}_{1}", x, y);
                interactables.Add(new Interactable {
                    FacePlayer = tile.facePlayer, transform = instance.transform, ID = x.ToString() + y.ToString()
                });

                DungeonObjectEvent co = instance.GetComponent <DungeonObjectEvent>();

                co.tile = tile;

                co.Location = new Location {
                    template = currentDungeonConfig, X = x, Y = y
                };

                if (Finder.party.InteractedObjects.Any(i => i.Location.Equals(co.Location)))
                {
                    co.SetInteraction(true);
                }

                if (tile.StartsDeactivated || Finder.party.DeactivatedObjects.Any(i => i.Location.Equals(co.Location)))
                {
                    co.Deactivate();
                }
                else
                {
                    co.Activate();
                }
            }
            else
            {
                Debug.LogErrorFormat("Error: No tile defined at position: {0}, {1}", x, y);
            }
        }
        // -------------------------------------------------------------------------------
        // ExecuteEventActions
        // -------------------------------------------------------------------------------
        protected void ExecuteEventActions(int id)
        {
            if (currentNode.choiceActions.Length == 0 ||
                currentNode.choiceActions.Length < id ||
                currentNode.choiceActions[id] == null)
            {
                return;
            }

            bool wait = false;

            // --------------------------------------------------------------------------- Play Sound

            Finder.audio.PlaySFX(currentNode.choiceActions[id].soundEffect);

            // --------------------------------------------------------------------------- Costs

            foreach (TemplateItem tmpl in currentNode.choiceActions[id].removeItems)
            {
                Finder.party.inventory.AddItem(tmpl, -1);
            }

            foreach (TemplateCharacterHero tmpl in currentNode.choiceActions[id].removeHeroes)
            {
                Finder.party.DismissHero(tmpl);
            }

            foreach (AbilityLevel tmpl in currentNode.choiceActions[id].castAbilities)
            {
                CharacterBase target = Finder.party.HasAbility(tmpl.template, tmpl.level);
                if (target != null)
                {
                    target.MP -= tmpl.template.GetCost(tmpl.level);
                }
            }

            if (currentNode.choiceActions[id].removeCurrencyAmount != 0)
            {
                Finder.party.currencies.setResource(currentNode.choiceActions[id].currencyType, currentNode.choiceActions[id].removeCurrencyAmount * -1);
            }

            // --------------------------------------------------------------------------- Rewards

            foreach (TemplateCharacterHero tmpl in currentNode.choiceActions[id].addHeroes)
            {
                if (tmpl.checkQuantity)
                {
                    Finder.party.AddHero(tmpl);
                }
            }

            if (currentNode.choiceActions[id].addItems.Length > 0)
            {
                RPGHelper.DropLoot(currentNode.choiceActions[id].addItems.ToList());
            }

            Finder.party.AddExperience(currentNode.choiceActions[id].addExperience);

            // --------------------------------------------------------------------------- Attack Party

            if (currentNode.choiceActions[id].attackAbility != null)
            {
                bool targetAll = false;

                if (currentNode.choiceActions[id].attackTarget == InteractableEventTarget.All)
                {
                    targetAll = true;
                }

                InstanceSkill instance = new InstanceSkill(currentNode.choiceActions[id].attackAbility, currentNode.choiceActions[id].attackAbilityLevel);

                ActionDamage(instance, targetAll);
            }

            // --------------------------------------------------------------------------- Cure Party

            if (currentNode.choiceActions[id].curativeAbility != null)
            {
                bool targetAll = false;

                if (currentNode.choiceActions[id].attackTarget == InteractableEventTarget.All)
                {
                    targetAll = true;
                }

                InstanceSkill instance = new InstanceSkill(currentNode.choiceActions[id].curativeAbility, currentNode.choiceActions[id].curativeAbilityLevel);

                ActionRecover(instance, targetAll);
            }

            // --------------------------------------------------------------------------- Manipulate other Event

            foreach (InteractableEventAction tmpl in currentNode.choiceActions[id].events)
            {
                string             name = string.Format("{0}_{1}", tmpl.targetX, tmpl.targetY);
                GameObject         go   = GameObject.Find(name);
                DungeonObjectEvent co   = go.GetComponent <DungeonObjectEvent>();

                if (go == null || co == null)
                {
                    Debug.Log(string.Format("Error: No event for condition at {0}/{1}", tmpl.targetX, tmpl.targetY));
                }

                if (tmpl.targetActivation == BoolType.True)
                {
                    co.Activate();
                }
                else if (tmpl.targetActivation == BoolType.False)
                {
                    co.Deactivate();
                }

                if (tmpl.targetInteraction == BoolType.True)
                {
                    co.AddInteraction();
                }
                else if (tmpl.targetInteraction == BoolType.False)
                {
                    co.RemoveInteraction();
                }
            }

            // --------------------------------------------------------------------------- Manipulate this Event

            if (currentNode.choiceActions[id].eventActivation == BoolType.True)
            {
                Activate();
            }
            else if (currentNode.choiceActions[id].eventActivation == BoolType.False)
            {
                Deactivate();
            }

            if (currentNode.choiceActions[id].eventInteraction == BoolType.True)
            {
                AddInteraction();
            }
            else if (currentNode.choiceActions[id].eventInteraction == BoolType.False)
            {
                RemoveInteraction();
            }

            // --------------------------------------------------------------------------- Animate Event

            if (currentNode.choiceActions[id].moveDirection != MoveType.None)
            {
                moveDirection = currentNode.choiceActions[id].moveDirection;
                IsMoving      = true;
            }

            // --------------------------------------------------------------------------- Teleportation

            if (currentNode.choiceActions[id].teleport.locationType != LocationType.None)
            {
                Finder.map.TeleportPlayer(currentNode.choiceActions[id].teleport);
            }

            // --------------------------------------------------------------------------- Open Shop

            if (currentNode.choiceActions[id].openShop != null)
            {
                Finder.ui.OverrideShopState(currentNode.choiceActions[id].openShop);
                Finder.ui.PushState(UIState.ShopOutside);
            }

            // --------------------------------------------------------------------------- Start Combat

            if (currentNode.choiceActions[id].startCombat)
            {
                int  BattlePoolId         = currentNode.choiceActions[id].battlePoolId;
                int  BattleEncLevel       = currentNode.choiceActions[id].battleEncounterLevel;
                int  BattleEncAmountMin   = currentNode.choiceActions[id].battleEncounterAmountMin;
                int  BattleEncAmountMax   = currentNode.choiceActions[id].battleEncounterAmountMax;
                bool BattleEncAmountScale = currentNode.choiceActions[id].battleEncounterAmountScale;

                Finder.battle.StartBattle(BattlePoolId, BattleEncLevel, BattleEncAmountMin, BattleEncAmountMax, BattleEncAmountScale, !tile.TriggerOnce);

                wait = true;
            }

            // --------------------------------------------------------------------------- Complete Event

            StartCoroutine(WaitForCompletion(id, wait));
        }
        // -------------------------------------------------------------------------------
        //
        // -------------------------------------------------------------------------------
        public bool CheckEventCondition(EventCondition condition)
        {
            if (condition == null)
            {
                return(true);
            }

            bool party_success   = false;
            bool item_success    = false;
            bool ability_success = false;
            bool event_success   = false;

            // --------------------------------------------------------------------------- Required Heroes

            if (condition.requiredHeroes.Length > 0)
            {
                foreach (TemplateCharacterHero tmpl in condition.requiredHeroes)
                {
                    party_success = Finder.party.HasMember(tmpl);

                    if (party_success && !condition.requiresAllHeroes && condition.requiredHeroes.Length > 1)
                    {
                        break;
                    }
                }
            }
            else
            {
                party_success = true;
            }

            // --------------------------------------------------------------------------- Required Items

            if (condition.items.Length > 0)
            {
                foreach (TemplateItem tmpl in condition.items)
                {
                    item_success = (Finder.party.inventory.GetQuantity(tmpl) > 0) ? true : false;

                    if (item_success && !condition.requiresAllItems && condition.items.Length > 1)
                    {
                        break;
                    }
                }
            }
            else
            {
                item_success = true;
            }

            // --------------------------------------------------------------------------- Required Abilities

            if (condition.abilities.Length > 0)
            {
                foreach (AbilityLevel tmpl in condition.abilities)
                {
                    CharacterBase character = Finder.party.HasAbility(tmpl.template, tmpl.level);
                    ability_success = (character != null) ? true : false;

                    if (ability_success)
                    {
                        ability_success = Finder.party.CanCastAbility(tmpl.template, tmpl.level);
                    }

                    if (ability_success && !condition.requiresAllAbilities && condition.abilities.Length > 1)
                    {
                        break;
                    }
                }
            }
            else
            {
                ability_success = true;
            }

            // --------------------------------------------------------------------------- Required Events

            if (condition.events.Length > 0)
            {
                foreach (InteractableEventCondition tmpl in condition.events)
                {
                    bool activate_success = true;
                    bool interact_success = true;

                    string             name = string.Format("{0}_{1}", tmpl.targetX, tmpl.targetY);
                    GameObject         go   = GameObject.Find(name);
                    DungeonObjectEvent co   = go.GetComponent <DungeonObjectEvent>();

                    if (go == null || co == null)
                    {
                        Debug.Log(string.Format("Error: No event for a condition at {0}/{1}", tmpl.targetX, tmpl.targetY));
                    }

                    if (tmpl.targetActivated != BoolType.Any)
                    {
                        activate_success = (co.deactivated && tmpl.targetActivated == BoolType.False) ||
                                           (!co.deactivated && tmpl.targetActivated == BoolType.True);
                    }

                    if (tmpl.targetInteracted != BoolType.Any)
                    {
                        interact_success = (co.deactivated && tmpl.targetActivated == BoolType.False) ||
                                           (!co.deactivated && tmpl.targetActivated == BoolType.True);
                    }

                    event_success = (activate_success && interact_success) ? true : event_success;

                    if (event_success == true && !condition.requiresAllEvents && condition.events.Length > 1)
                    {
                        break;
                    }
                }
            }
            else
            {
                event_success = true;
            }

            // --------------------------------------------------------------------------- Validate Completion

            return(party_success && item_success && ability_success && event_success);
        }