Esempio n. 1
0
        public void Main()
        {
            NWObject door   = NWGameObject.OBJECT_SELF;
            NWArea   area   = door.Area;
            NWPlayer player = GetClickingObject();

            if (!player.IsValid)
            {
                player = GetLastUsedBy();
            }

            int remainingKeyCards = area.GetLocalInt("KEY_CARDS_REMAINING");

            if (remainingKeyCards > 0)
            {
                player.FloatingText("You need " + remainingKeyCards + "x key card(s) to access this elevator.");
            }
            else
            {
                player.FloatingText("You access the elevator with the found key cards.");
                string     destinationWPTag    = door.GetLocalString("DESTINATION_WAYPOINT");
                string     destinationAreaTag  = door.GetLocalString("DESTINATION_AREA_TAG");
                NWArea     destinationArea     = area.GetLocalObject(destinationAreaTag);
                NWLocation destinationLocation = GetLocation(GetNearestObjectByTag(destinationWPTag, GetFirstObjectInArea(destinationArea)));

                player.AssignCommand(() => { ActionJumpToLocation(destinationLocation); });
            }
        }
Esempio n. 2
0
        public bool Run(params object[] args)
        {
            int      index           = (int)args[0];
            int      customRuleIndex = (int)args[1];
            NWPlayer player          = _.GetPCSpeaker();
            NWObject talkTo          = Object.OBJECT_SELF;
            int      questID         = talkTo.GetLocalInt("QUEST_ID_" + index);

            if (questID <= 0)
            {
                questID = talkTo.GetLocalInt("QST_ID_" + index);
            }

            if (_data.GetAll <Quest>().All(x => x.ID != questID))
            {
                _.SpeakString("ERROR: Quest #" + index + " is improperly configured. Please notify an admin");
                return(false);
            }

            string rule     = string.Empty;
            string ruleArgs = string.Empty;

            if (customRuleIndex > 0)
            {
                string ruleName = "QUEST_ID_" + index + "_RULE_" + customRuleIndex;
                rule     = talkTo.GetLocalString(ruleName);
                ruleArgs = talkTo.GetLocalString("QUEST_ID_" + index + "_RULE_ARGS_" + customRuleIndex);

                if (string.IsNullOrWhiteSpace(rule))
                {
                    _.SpeakString("ERROR: Quest #" + index + ", rule #" + customRuleIndex + " is improperly configured. Please notify an admin.");
                    return(false);
                }
            }

            _quest.CompleteQuest(player, talkTo, questID, null);

            if (!string.IsNullOrWhiteSpace(rule))
            {
                Quest quest = _data.Single <Quest>(x => x.ID == questID);
                App.ResolveByInterface <IQuestRule>("QuestRule." + rule, ruleAction =>
                {
                    string[] argsArray = null;

                    if (string.IsNullOrWhiteSpace(ruleArgs))
                    {
                        ruleArgs = quest.OnCompleteArgs;
                    }

                    if (!string.IsNullOrWhiteSpace(ruleArgs))
                    {
                        argsArray = ruleArgs.Split(',');
                    }
                    ruleAction.Run(player, talkTo, questID, argsArray);
                });
            }

            return(true);
        }
Esempio n. 3
0
        public static bool Check(int index, int customRuleIndex)
        {
            using (new Profiler(nameof(QuestComplete) + ".Index" + index + ".Rule" + customRuleIndex))
            {
                NWPlayer player  = _.GetPCSpeaker();
                NWObject talkTo  = NWGameObject.OBJECT_SELF;
                int      questID = talkTo.GetLocalInt("QUEST_ID_" + index);
                if (questID <= 0)
                {
                    questID = talkTo.GetLocalInt("QST_ID_" + index);
                }

                if (!DataService.Quest.ExistsByID(questID))
                {
                    _.SpeakString("ERROR: Quest #" + index + " is improperly configured. Please notify an admin");
                    return(false);
                }

                string rule     = string.Empty;
                string ruleArgs = string.Empty;
                if (customRuleIndex > 0)
                {
                    string ruleName = "QUEST_ID_" + index + "_RULE_" + customRuleIndex;
                    rule     = talkTo.GetLocalString(ruleName);
                    ruleArgs = talkTo.GetLocalString("QUEST_ID_" + index + "_RULE_ARGS_" + customRuleIndex);

                    if (string.IsNullOrWhiteSpace(rule))
                    {
                        _.SpeakString("ERROR: Quest #" + index + ", rule #" + customRuleIndex + " is improperly configured. Please notify an admin.");
                        return(false);
                    }
                }

                QuestService.CompleteQuest(player, talkTo, questID, null);

                if (!string.IsNullOrWhiteSpace(rule))
                {
                    Data.Entity.Quest quest = DataService.Quest.GetByID(questID);
                    var ruleAction          = QuestService.GetQuestRule(rule);

                    string[] argsArray = null;

                    if (string.IsNullOrWhiteSpace(ruleArgs))
                    {
                        ruleArgs = quest.OnCompleteArgs;
                    }

                    if (!string.IsNullOrWhiteSpace(ruleArgs))
                    {
                        argsArray = ruleArgs.Split(',');
                    }

                    ruleAction.Run(player, talkTo, questID, argsArray);
                }

                return(true);
            }
        }
Esempio n. 4
0
        private static void HandleTriggerAndPlaceableQuestLogic(NWPlayer oPC, NWObject oObject)
        {
            if (!oPC.IsPlayer)
            {
                return;
            }
            string questMessage       = oObject.GetLocalString("QUEST_MESSAGE");
            int    questID            = oObject.GetLocalInt("QUEST_ID");
            int    questSequence      = oObject.GetLocalInt("QUEST_SEQUENCE");
            string visibilityObjectID = oObject.GetLocalString("VISIBILITY_OBJECT_ID");

            if (questID <= 0)
            {
                oPC.SendMessage("QUEST_ID variable not set on object. Please inform admin this quest is bugged. (QuestID: " + questID + ")");
                return;
            }

            if (questSequence <= 0)
            {
                oPC.SendMessage("QUEST_SEQUENCE variable not set on object. Please inform admin this quest is bugged. (QuestID: " + questID + ")");
                return;
            }

            PCQuestStatus pcQuestStatus = DataService.SingleOrDefault <PCQuestStatus>(x => x.PlayerID == oPC.GlobalID && x.QuestID == questID);

            if (pcQuestStatus == null)
            {
                return;
            }

            QuestState questState = DataService.Get <QuestState>(pcQuestStatus.CurrentQuestStateID);

            if (questState.Sequence != questSequence ||
                (questState.QuestTypeID != (int)QuestType.UseObject &&
                 questState.QuestTypeID != (int)QuestType.ExploreArea))
            {
                return;
            }


            if (!string.IsNullOrWhiteSpace(questMessage))
            {
                _.DelayCommand(1.0f, () =>
                {
                    oPC.SendMessage(questMessage);
                });
            }

            AdvanceQuestState(oPC, oObject, questID);

            if (!string.IsNullOrWhiteSpace(visibilityObjectID))
            {
                ObjectVisibilityService.AdjustVisibility(oPC, oObject, false);
            }
        }
        public void Main()
        {
            NWPlayer   player                 = GetClickingObject();
            NWObject   door                   = NWGameObject.OBJECT_SELF;
            string     destinationAreaTag     = door.GetLocalString("DESTINATION_AREA_TAG");
            string     destinationWaypointTag = door.GetLocalString("DESTINATION_WAYPOINT");
            NWArea     area                   = door.Area.GetLocalObject(destinationAreaTag);
            NWObject   waypoint               = GetNearestObjectByTag(destinationWaypointTag, GetFirstObjectInArea(area));
            NWLocation location               = waypoint.Location;

            player.AssignCommand(() => { ActionJumpToLocation(location); });
        }
Esempio n. 6
0
        /// <summary>
        /// Progresses a player to the next state if they meet all requirements to do so.
        /// </summary>
        /// <param name="player">The player object</param>
        /// <param name="trigger">The trigger or placeable being used/entered.</param>
        private static void HandleTriggerAndPlaceableQuestLogic(NWPlayer player, NWObject trigger)
        {
            if (!player.IsPlayer)
            {
                return;
            }
            string questMessage       = trigger.GetLocalString("QUEST_MESSAGE");
            int    questID            = trigger.GetLocalInt("QUEST_ID");
            int    questState         = trigger.GetLocalInt("QUEST_STATE");
            string visibilityObjectID = trigger.GetLocalString("VISIBILITY_OBJECT_ID");

            if (questID <= 0)
            {
                player.SendMessage("QUEST_ID variable not set on object. Please inform admin this quest is bugged. (QuestID: " + questID + ")");
                return;
            }

            if (questState <= 0)
            {
                player.SendMessage("QUEST_STATE variable not set on object. Please inform admin this quest is bugged. (QuestID: " + questID + ")");
                return;
            }

            PCQuestStatus pcQuestStatus = DataService.PCQuestStatus.GetByPlayerAndQuestIDOrDefault(player.GlobalID, questID);

            if (pcQuestStatus == null)
            {
                return;
            }


            if (pcQuestStatus.QuestState != questState)
            {
                return;
            }

            if (!string.IsNullOrWhiteSpace(questMessage))
            {
                DelayCommand(1.0f, () =>
                {
                    player.SendMessage(questMessage);
                });
            }

            var quest = GetQuestByID(questID);

            quest.Advance(player, trigger);

            if (!string.IsNullOrWhiteSpace(visibilityObjectID))
            {
                ObjectVisibilityService.AdjustVisibility(player, trigger, false);
            }
        }
Esempio n. 7
0
        public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData)
        {
            Location effectLocation;
            NWPlayer player = (user.Object);

            if (!string.IsNullOrWhiteSpace(target.GetLocalString("RESOURCE_RESREF")))
            {
                ScanResource(user, target);
                DurabilityService.RunItemDecay(player, item, RandomService.RandomFloat(0.05f, 0.1f));
                effectLocation = target.Location;
            }
            else
            {
                user.FloatingText("You cannot scan that object with this type of scanner.");
                return;
            }

            _.ApplyEffectAtLocation(DurationType.Instant, _.EffectVisualEffect(VisualEffect.Vfx_Fnf_Summon_Monster_3), effectLocation);

            if (user.IsPlayer && GetLocalBool(user, target.GlobalID.ToString()) == false)
            {
                int scanningBonus = item.ScanningBonus;
                SkillService.GiveSkillXP(player, SkillType.Harvesting, 150);
                user.SetLocalInt(target.GlobalID.ToString(), 1 + scanningBonus);
            }
        }
Esempio n. 8
0
        public bool Run(params object[] args)
        {
            NWPlayer player   = _.GetPCSpeaker();
            NWObject self     = Object.OBJECT_SELF;
            string   storeTag = self.GetLocalString("STORE_TAG");
            NWObject store;

            if (string.IsNullOrWhiteSpace(storeTag))
            {
                store = _.GetNearestObject(OBJECT_TYPE_STORE, self);
            }
            else
            {
                store = _.GetObjectByTag(storeTag);
            }

            if (!store.IsValid)
            {
                _.SpeakString("ERROR: Unable to locate store.");
            }

            _.OpenStore(store, player);

            return(true);
        }
        public void CopyVariables(NWObject oSource, NWObject oCopy)
        {
            int variableCount = _nwnxObject.GetLocalVariableCount(oSource);

            for (int variableIndex = 0; variableIndex < variableCount - 1; variableIndex++)
            {
                LocalVariable stCurVar = _nwnxObject.GetLocalVariable(oSource, variableIndex);

                switch (stCurVar.Type)
                {
                case LocalVariableType.Int:
                    oCopy.SetLocalInt(stCurVar.Key, oSource.GetLocalInt(stCurVar.Key));
                    break;

                case LocalVariableType.Float:
                    oCopy.SetLocalFloat(stCurVar.Key, oSource.GetLocalFloat(stCurVar.Key));
                    break;

                case LocalVariableType.String:
                    oCopy.SetLocalString(stCurVar.Key, oSource.GetLocalString(stCurVar.Key));
                    break;

                case LocalVariableType.Object:
                    oCopy.SetLocalObject(stCurVar.Key, oSource.GetLocalObject(stCurVar.Key));
                    break;

                case LocalVariableType.Location:
                    oCopy.SetLocalLocation(stCurVar.Key, oSource.GetLocalLocation(stCurVar.Key));
                    break;
                }
            }
        }
Esempio n. 10
0
        public static void Main()
        {
            using (new Profiler(nameof(open_store)))
            {
                NWPlayer player   = _.GetPCSpeaker();
                NWObject self     = _.OBJECT_SELF;
                string   storeTag = self.GetLocalString("STORE_TAG");
                NWObject store;

                if (string.IsNullOrWhiteSpace(storeTag))
                {
                    store = _.GetNearestObject(self, ObjectType.Store);
                }
                else
                {
                    store = _.GetObjectByTag(storeTag);
                }

                if (!store.IsValid)
                {
                    _.SpeakString("ERROR: Unable to locate store.");
                }

                _.OpenStore(store, player);
            }
        }
Esempio n. 11
0
        public override void Initialize()
        {
            NWObject   door       = NWGameObject.OBJECT_SELF;
            NWPlayer   player     = GetPC();
            List <int> keyItemIDs = new List <int>();

            int count     = 1;
            int keyItemID = door.GetLocalInt("REQUIRED_KEY_ITEM_ID_" + count);

            while (keyItemID > 0)
            {
                keyItemIDs.Add(keyItemID);

                count++;
                keyItemID = door.GetLocalInt("REQUIRED_KEY_ITEM_ID_" + count);
            }

            bool   hasKeyItems  = KeyItemService.PlayerHasAllKeyItems(player, keyItemIDs.ToArray());
            string doorDialogue = door.GetLocalString("DOOR_DIALOGUE");

            if (!string.IsNullOrWhiteSpace(doorDialogue))
            {
                SetPageHeader("MainPage", doorDialogue);
            }

            if (hasKeyItems)
            {
                SetResponseText("MainPage", 1, "Open Door");
            }
            else
            {
                SetResponseVisible("MainPage", 1, false);
            }
        }
Esempio n. 12
0
        public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData)
        {
            Location effectLocation;
            NWPlayer player = (user.Object);

            // Targeted a location or self. Locate nearest resource.
            if (!target.IsValid || Equals(user, target))
            {
                ScanArea(user, targetLocation);
                _durability.RunItemDecay(player, item, _random.RandomFloat(0.02f, 0.08f));
                effectLocation = targetLocation;
            }
            else if (!string.IsNullOrWhiteSpace(target.GetLocalString("RESOURCE_RESREF")))
            {
                ScanResource(user, target);
                _durability.RunItemDecay(player, item, _random.RandomFloat(0.05f, 0.1f));
                effectLocation = target.Location;
            }
            else
            {
                user.FloatingText("You cannot scan that object with this type of scanner.");
                return;
            }

            _.ApplyEffectAtLocation(DURATION_TYPE_INSTANT, _.EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_3), effectLocation);

            if (user.IsPlayer && user.GetLocalInt(target.GlobalID.ToString()) == FALSE)
            {
                int scanningBonus = item.ScanningBonus;
                _skill.GiveSkillXP(player, SkillType.Harvesting, 150);
                user.SetLocalInt(target.GlobalID.ToString(), 1 + scanningBonus);
            }
        }
Esempio n. 13
0
        public static void Run(string variableName)
        {
            NWObject self   = (NWGameObject.OBJECT_SELF);
            string   script = self.GetLocalString(variableName);

            using (new Profiler("ScriptEvent." + script))
            {
                string rootNamespace   = Assembly.GetExecutingAssembly().GetName().Name;
                string scriptNamespace = rootNamespace + ".Scripts." + script;

                // Check the script cache first. If it exists, we run it.
                if (ScriptService.IsScriptRegisteredByNamespace(scriptNamespace))
                {
                    ScriptService.RunScriptByNamespace(scriptNamespace);
                    return;
                }

                // Otherwise look for a script contained by the app.
                scriptNamespace = rootNamespace + "." + script;
                Type type = Type.GetType(scriptNamespace);

                if (type == null)
                {
                    Console.WriteLine("Unable to locate type for ScriptEvent: " + script);
                    return;
                }

                IRegisteredEvent @event = Activator.CreateInstance(type) as IRegisteredEvent;
                @event?.Run();
            }
        }
Esempio n. 14
0
        private void HandleItemSpecificCastSpell()
        {
            NWObject oSpellOrigin = (_.GetSpellCastItem());
            // Item specific
            string script = oSpellOrigin.GetLocalString("JAVA_SCRIPT");

            if (!string.IsNullOrWhiteSpace(script))
            {
                App.RunEvent <LegacyJVMItemEvent>(script);
            }
        }
Esempio n. 15
0
        public bool OnModuleExamine(NWPlayer examiner, NWObject target)
        {
            string backupDescription = target.GetLocalString("BACKUP_DESCRIPTION");

            if (!string.IsNullOrWhiteSpace(backupDescription))
            {
                target.UnidentifiedDescription = backupDescription;
            }

            if (!examiner.IsDM || !target.IsPlayer || target.IsDM)
            {
                return(false);
            }

            backupDescription = target.IdentifiedDescription;
            target.SetLocalString("BACKUP_DESCRIPTION", backupDescription);

            Player playerEntity    = _data.Single <Player>(x => x.ID == target.GlobalID);
            NWArea area            = NWModule.Get().Areas.Single(x => x.Resref == playerEntity.RespawnAreaResref);
            string respawnAreaName = area.Name;

            StringBuilder description =
                new StringBuilder(
                    _color.Green("ID: ") + target.GlobalID + "\n" +
                    _color.Green("Character Name: ") + target.Name + "\n" +
                    _color.Green("Respawn Area: ") + respawnAreaName + "\n" +
                    _color.Green("Skill Points: ") + playerEntity.TotalSPAcquired + " (Unallocated: " + playerEntity.UnallocatedSP + ")" + "\n" +
                    _color.Green("FP: ") + playerEntity.CurrentFP + " / " + playerEntity.MaxFP + "\n" +
                    _color.Green("Skill Levels: ") + "\n\n");

            List <PCSkill> pcSkills = _skill.GetAllPCSkills(target.Object);

            foreach (PCSkill pcSkill in pcSkills)
            {
                Skill skill = _skill.GetSkill(pcSkill.SkillID);
                description.Append(skill.Name).Append(" rank ").Append(pcSkill.Rank).AppendLine();
            }

            description.Append("\n\n").Append(_color.Green("Perks: ")).Append("\n\n");

            var pcPerks = _data.Where <PCPerk>(x => x.PlayerID == target.GlobalID);

            foreach (PCPerk pcPerk in pcPerks)
            {
                var perk = _data.Get <Data.Entity.Perk>(pcPerk.PerkID);
                description.Append(perk.Name).Append(" Lvl. ").Append(pcPerk.PerkLevel).AppendLine();
            }

            description.Append("\n\n").Append(_color.Green("Description: \n\n")).Append(backupDescription).AppendLine();
            target.UnidentifiedDescription = description.ToString();

            return(true);
        }
        public bool OnModuleExamine(NWPlayer examiner, NWObject target)
        {
            string backupDescription = target.GetLocalString("BACKUP_DESCRIPTION");

            if (!string.IsNullOrWhiteSpace(backupDescription))
            {
                target.UnidentifiedDescription = backupDescription;
            }

            if (!examiner.IsDM || !target.IsPlayer || target.IsDM)
            {
                return(false);
            }

            backupDescription = target.IdentifiedDescription;
            target.SetLocalString("BACKUP_DESCRIPTION", backupDescription);

            PlayerCharacter playerEntity    = _db.PlayerCharacters.Single(x => x.PlayerID == target.GlobalID);
            string          respawnAreaName = _.GetName(_.GetObjectByTag(playerEntity.RespawnAreaTag));

            StringBuilder description =
                new StringBuilder(
                    _color.Green("ID: ") + target.GlobalID + "\n" +
                    _color.Green("Character Name: ") + target.Name + "\n" +
                    _color.Green("Respawn Area: ") + respawnAreaName + "\n" +
                    _color.Green("Skill Points: ") + playerEntity.TotalSPAcquired + " (Unallocated: " + playerEntity.UnallocatedSP + ")" + "\n" +
                    _color.Green("Nourishment: ") + playerEntity.CurrentHunger + " / " + playerEntity.MaxHunger + "\n" +
                    _color.Green("Mana: ") + playerEntity.CurrentMana + " / " + playerEntity.MaxMana + "\n" +
                    _color.Green("Skill Levels: ") + "\n\n");

            List <PCSkill> pcSkills = _db.PCSkills.Where(x => x.PlayerID == target.GlobalID && x.Skill.IsActive).ToList();

            foreach (PCSkill skill in pcSkills)
            {
                description.Append(skill.Skill.Name).Append(" rank ").Append(skill.Rank).AppendLine();
            }

            description.Append("\n\n").Append(_color.Green("Perks: ")).Append("\n\n");

            List <PCPerkHeader> pcPerks = _db.StoredProcedure <PCPerkHeader>("GetPCPerksForMenuHeader",
                                                                             new SqlParameter("PlayerID", target.GlobalID));

            foreach (PCPerkHeader perk in pcPerks)
            {
                description.Append(perk.Name).Append(" Lvl. ").Append(perk.Level).AppendLine();
            }

            description.Append("\n\n").Append(_color.Green("Description: \n\n")).Append(backupDescription).AppendLine();
            target.UnidentifiedDescription = description.ToString();

            return(true);
        }
Esempio n. 17
0
        public static void Main()
        {
            using (new Profiler(nameof(warp_to_wp)))
            {
                NWPlayer player    = _.GetPCSpeaker();
                NWObject talkingTo = NWGameObject.OBJECT_SELF;

                string   waypointTag = talkingTo.GetLocalString("DESTINATION");
                NWObject waypoint    = _.GetWaypointByTag(waypointTag);

                player.AssignCommand(() => { _.ActionJumpToLocation(waypoint.Location); });
            }
        }
Esempio n. 18
0
        private void HandleTriggerAndPlaceableQuestLogic(NWPlayer oPC, NWObject oObject)
        {
            if (!oPC.IsPlayer)
            {
                return;
            }
            string questMessage  = oObject.GetLocalString("QUEST_MESSAGE");
            int    questID       = oObject.GetLocalInt("QUEST_ID");
            int    questSequence = oObject.GetLocalInt("QUEST_SEQUENCE");

            if (questID <= 0)
            {
                oPC.SendMessage("QUEST_ID variable not set on object. Please inform admin this quest is bugged.");
                return;
            }

            if (questSequence <= 0)
            {
                oPC.SendMessage("QUEST_SEQUENCE variable not set on object. Please inform admin this quest is bugged. (QuestID: " + questID + ")");
                return;
            }

            PCQuestStatus pcQuestStatus = _db.PCQuestStatus.Single(x => x.PlayerID == oPC.GlobalID && x.QuestID == questID);

            if (pcQuestStatus == null)
            {
                return;
            }

            QuestState questState = pcQuestStatus.CurrentQuestState;

            if (questState.Sequence == questSequence ||
                (questState.QuestTypeID != (int)QuestType.UseObject &&
                 questState.QuestTypeID != (int)QuestType.ExploreArea))
            {
                return;
            }


            if (!string.IsNullOrWhiteSpace(questMessage))
            {
                oPC.DelayCommand(() =>
                {
                    oPC.SendMessage(questMessage);
                }, 1.0f);
            }

            AdvanceQuestState(oPC, questID);
        }
Esempio n. 19
0
        public bool Run(params object[] args)
        {
            NWPlayer player    = _.GetPCSpeaker();
            NWObject talkingTo = Object.OBJECT_SELF;

            string   waypointTag = talkingTo.GetLocalString("DESTINATION");
            NWObject waypoint    = _.GetWaypointByTag(waypointTag);

            player.AssignCommand(() =>
            {
                _.ActionJumpToLocation(waypoint.Location);
            });

            return(true);
        }
        public void AdjustVisibility(NWPlayer player, NWObject target, bool isVisible)
        {
            if (!player.IsPlayer)
            {
                return;
            }
            if (target.IsPlayer || target.IsDM)
            {
                return;
            }

            string visibilityObjectID = target.GetLocalString("VISIBILITY_OBJECT_ID");

            if (string.IsNullOrWhiteSpace(visibilityObjectID))
            {
                target.AssignCommand(() =>
                {
                    _.SpeakString("Unable to locate VISIBILITY_OBJECT_ID variable. Need this in order to adjust visibility. Notify an admin if you see this message.");
                });
                return;
            }

            var visibility            = _data.SingleOrDefault <PCObjectVisibility>(x => x.PlayerID == player.GlobalID && x.VisibilityObjectID == visibilityObjectID);
            DatabaseActionType action = DatabaseActionType.Update;

            if (visibility == null)
            {
                visibility = new PCObjectVisibility
                {
                    PlayerID           = player.GlobalID,
                    VisibilityObjectID = visibilityObjectID
                };
                action = DatabaseActionType.Insert;
            }

            visibility.IsVisible = isVisible;
            _data.SubmitDataChange(visibility, action);

            if (visibility.IsVisible)
            {
                _nwnxPlayer.SetVisibilityOverride(player, target, (int)PlayerVisibilityType.Visible);
            }
            else
            {
                _nwnxPlayer.SetVisibilityOverride(player, target, (int)PlayerVisibilityType.Hidden);
            }
        }
Esempio n. 21
0
        public bool Run(params object[] args)
        {
            NWObject self   = NWObject.Wrap(Object.OBJECT_SELF);
            string   script = self.GetLocalString((string)args[0]);

            Type type = Type.GetType(Assembly.GetExecutingAssembly().GetName().Name + "." + script);

            if (type == null)
            {
                Console.WriteLine("Unable to locate type for LegacyJVMEvent: " + script);
                return(false);
            }

            App.RunEvent(type);

            return(true);
        }
Esempio n. 22
0
        public void ApplyVisibilityForObject(NWObject target)
        {
            string visibilityObjectID = target.GetLocalString("VISIBILITY_OBJECT_ID");

            if (string.IsNullOrWhiteSpace(visibilityObjectID))
            {
                return;
            }
            Guid visibilityGUID = new Guid(visibilityObjectID);

            if (!_appCache.VisibilityObjects.ContainsKey(visibilityGUID))
            {
                _appCache.VisibilityObjects.Add(visibilityGUID, target);
            }
            else
            {
                _appCache.VisibilityObjects[visibilityGUID] = target;
            }

            var players         = NWModule.Get().Players.ToList();
            var concatPlayerIDs = players.Select(x => x.GlobalID);
            var pcVisibilities  = _data.Where <PCObjectVisibility>(x => concatPlayerIDs.Contains(x.PlayerID)).ToList();

            foreach (var player in players)
            {
                var visibility = pcVisibilities.SingleOrDefault(x => x.PlayerID == player.GlobalID && x.VisibilityObjectID == visibilityGUID);

                if (visibility == null)
                {
                    if (target.GetLocalInt("VISIBILITY_HIDDEN_DEFAULT") == TRUE)
                    {
                        _nwnxPlayer.SetVisibilityOverride(player, target, (int)PlayerVisibilityType.Hidden);
                    }
                    continue;
                }

                if (visibility.IsVisible)
                {
                    _nwnxPlayer.SetVisibilityOverride(player, target, (int)PlayerVisibilityType.Visible);
                }
                else
                {
                    _nwnxPlayer.SetVisibilityOverride(player, target, (int)PlayerVisibilityType.Hidden);
                }
            }
        }
        public void OnModuleLoad()
        {
            foreach (var area in NWModule.Get().Areas)
            {
                NWObject obj = _.GetFirstObjectInArea(area);
                while (obj.IsValid)
                {
                    string visibilityObjectID = obj.GetLocalString("VISIBILITY_OBJECT_ID");
                    if (!string.IsNullOrWhiteSpace(visibilityObjectID))
                    {
                        _appCache.VisibilityObjects.Add(visibilityObjectID, obj);
                    }

                    obj = _.GetNextObjectInArea(area);
                }
            }
        }
Esempio n. 24
0
        private void HandleItemSpecificCastSpell()
        {
            NWObject oSpellOrigin = NWObject.Wrap(_.GetSpellCastItem());
            // Item specific
            string script = oSpellOrigin.GetLocalString("JAVA_SCRIPT");

            if (!string.IsNullOrWhiteSpace(script))
            {
                // Remove "Item." prefix if it exists.
                if (script.StartsWith("Item."))
                {
                    script = script.Substring(5);
                }

                App.RunEvent <LegacyJVMEvent>("Item." + script);
            }
        }
Esempio n. 25
0
        public static void ApplyVisibilityForObject(NWObject target)
        {
            string visibilityObjectID = target.GetLocalString("VISIBILITY_OBJECT_ID");

            if (string.IsNullOrWhiteSpace(visibilityObjectID))
            {
                return;
            }

            if (!AppCache.VisibilityObjects.ContainsKey(visibilityObjectID))
            {
                AppCache.VisibilityObjects.Add(visibilityObjectID, target);
            }
            else
            {
                AppCache.VisibilityObjects[visibilityObjectID] = target;
            }

            var players         = NWModule.Get().Players.ToList();
            var concatPlayerIDs = players.Select(x => x.GlobalID);
            var pcVisibilities  = DataService.PCObjectVisibility.GetAllByPlayerIDsAndVisibilityObjectID(concatPlayerIDs, visibilityObjectID).ToList();

            foreach (var player in players)
            {
                var visibility = pcVisibilities.SingleOrDefault(x => x.PlayerID == player.GlobalID);

                if (visibility == null)
                {
                    if (target.GetLocalInt("VISIBILITY_HIDDEN_DEFAULT") == TRUE)
                    {
                        NWNXVisibility.SetVisibilityOverride(player, target, VisibilityType.Hidden);
                    }
                    continue;
                }

                if (visibility.IsVisible)
                {
                    NWNXVisibility.SetVisibilityOverride(player, target, VisibilityType.Visible);
                }
                else
                {
                    NWNXVisibility.SetVisibilityOverride(player, target, VisibilityType.Hidden);
                }
            }
        }
Esempio n. 26
0
        private static void OnHitCastSpell()
        {
            NWObject target = NWGameObject.OBJECT_SELF;

            if (!target.IsValid)
            {
                return;
            }

            NWObject oSpellOrigin = (_.GetSpellCastItem());
            // Item specific
            string script = oSpellOrigin.GetLocalString("SCRIPT");

            if (!string.IsNullOrWhiteSpace(script))
            {
                ScriptItemEvent.Run(script);
            }
        }
Esempio n. 27
0
        public override void DoAction(NWPlayer player, string pageName, int responseID)
        {
            if (responseID != 1)
            {
                return;
            }

            NWObject door     = NWGameObject.OBJECT_SELF;
            string   insideWP = door.GetLocalString("LOCKED_DOOR_INSIDE_WP");
            NWObject wp       = _.GetWaypointByTag(insideWP);
            Location portTo   = wp.Location;

            _.AssignCommand(player, () =>
            {
                _.ActionJumpToLocation(portTo);
            });

            EndConversation();
        }
Esempio n. 28
0
        public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData)
        {
            string growingPlantID = target.GetLocalString("GROWING_PLANT_ID");

            if (string.IsNullOrWhiteSpace(growingPlantID))
            {
                user.SendMessage("Water jugs can only target growing plants.");
                return;
            }
            GrowingPlant growingPlant = DataService.Single <GrowingPlant>(x => x.ID == new Guid(growingPlantID));
            var          plant        = DataService.Get <Plant>(growingPlant.PlantID);

            if (growingPlant.WaterStatus <= 0)
            {
                user.SendMessage("That plant doesn't need to be watered at this time.");
                return;
            }

            if (item.Charges <= 0)
            {
                user.SendMessage("There's no water in that jug!");
                return;
            }

            int remainingTicks = growingPlant.RemainingTicks;

            if (growingPlant.WaterStatus > 1)
            {
                remainingTicks = remainingTicks / 2;
            }

            growingPlant.WaterStatus    = 0;
            growingPlant.RemainingTicks = remainingTicks;
            DataService.SubmitDataChange(growingPlant, DatabaseActionType.Update);

            user.SendMessage("You water the plant.");

            int rank = SkillService.GetPCSkillRank((NWPlayer)user, SkillType.Farming);

            int xp = (int)SkillService.CalculateRegisteredSkillLevelAdjustedXP(100, plant.Level, rank);

            SkillService.GiveSkillXP((NWPlayer)user, SkillType.Farming, xp);
        }
Esempio n. 29
0
        public static void Run(string variableName)
        {
            NWObject self   = (Object.OBJECT_SELF);
            string   script = self.GetLocalString(variableName);

            using (new Profiler("LegacyJVMEvent." + script))
            {
                Type type = Type.GetType(Assembly.GetExecutingAssembly().GetName().Name + "." + script);

                if (type == null)
                {
                    Console.WriteLine("Unable to locate type for LegacyJVMEvent: " + script);
                    return;
                }

                IRegisteredEvent @event = Activator.CreateInstance(type) as IRegisteredEvent;
                @event?.Run();
            }
        }
Esempio n. 30
0
        public static void Run(string variableName)
        {
            NWObject self   = (_.OBJECT_SELF);
            string   script = self.GetLocalString(variableName);

            using (new Profiler("ScriptEvent." + script))
            {
                string rootNamespace   = Assembly.GetExecutingAssembly().GetName().Name;
                string scriptNamespace = rootNamespace + ".Scripts." + script;

                // Check the script cache first. If it exists, we run it.
                if (ScriptService.IsScriptRegisteredByNamespace(scriptNamespace))
                {
                    ScriptService.RunScriptByNamespace(scriptNamespace);
                }
                else
                {
                    Console.WriteLine("Unable to locate script: " + scriptNamespace);
                }
            }
        }