Beispiel #1
0
        public bool Run(params object[] args)
        {
            NWPlayer    clicker = (_.GetPlaceableLastClickedBy());
            NWPlaceable tower   = (Object.OBJECT_SELF);

            clicker.ClearAllActions();
            if (!clicker.IsPlayer)
            {
                return(false);
            }
            if (_.GetDistanceBetween(clicker.Object, tower.Object) > 5.0f)
            {
                clicker.SendMessage("You are too far away to interact with that control tower.");
                return(false);
            }
            Guid            structureID = new Guid(tower.GetLocalString("PC_BASE_STRUCTURE_ID"));
            PCBaseStructure structure   = _data.Single <PCBaseStructure>(x => x.ID == structureID);

            if (_perm.HasBasePermission(clicker, structure.PCBaseID, BasePermission.CanManageBaseFuel))
            {
                _dialog.StartConversation(clicker, tower, "ControlTower");
            }
            else
            {
                clicker.SendMessage("You don't have permission to interact with this control tower.");
            }

            return(true);
        }
Beispiel #2
0
        public void OnPlayerDying()
        {
            NWPlayer oPC = NWPlayer.Wrap(_.GetLastPlayerDying());

            oPC.ClearAllActions();
            DeathFunction(oPC, 8);
        }
Beispiel #3
0
        private static void OnModuleUseFeat()
        {
            NWPlayer pc     = Object.OBJECT_SELF;
            int      featID = NWNXEvents.OnFeatUsed_GetFeatID();

            if (featID != (int)CustomFeatType.RenameCraftedItem)
            {
                return;
            }
            pc.ClearAllActions();

            bool   isSetting  = pc.GetLocalInt("CRAFT_RENAMING_ITEM") == TRUE;
            NWItem renameItem = NWNXEvents.OnFeatUsed_GetTarget().Object;

            if (isSetting)
            {
                pc.SendMessage("You are no longer naming an item.");
                pc.DeleteLocalInt("CRAFT_RENAMING_ITEM");
                pc.DeleteLocalObject("CRAFT_RENAMING_ITEM_OBJECT");
                return;
            }

            string crafterPlayerID = renameItem.GetLocalString("CRAFTER_PLAYER_ID");

            if (string.IsNullOrWhiteSpace(crafterPlayerID) || new Guid(crafterPlayerID) != pc.GlobalID)
            {
                pc.SendMessage("You may only rename items which you have personally crafted.");
                return;
            }

            pc.SetLocalInt("CRAFT_RENAMING_ITEM", TRUE);
            pc.SetLocalObject("CRAFT_RENAMING_ITEM_OBJECT", renameItem);
            pc.SendMessage("Please enter in a name for this item. Length should be between 3 and 64 characters. Use this feat again to cancel this procedure.");
        }
Beispiel #4
0
        private static void OnModuleUseFeat()
        {
            NWPlayer pc     = _.OBJECT_SELF;
            int      featID = Convert.ToInt32(NWNXEvents.GetEventData("FEAT_ID"));

            if (featID != (int)Feat.RenameCraftedItem)
            {
                return;
            }
            pc.ClearAllActions();

            bool   isSetting  = GetLocalBool(pc, "CRAFT_RENAMING_ITEM") == true;
            NWItem renameItem = NWNXObject.StringToObject(NWNXEvents.GetEventData("TARGET_OBJECT_ID"));

            if (isSetting)
            {
                pc.SendMessage("You are no longer naming an item.");
                pc.DeleteLocalInt("CRAFT_RENAMING_ITEM");
                pc.DeleteLocalObject("CRAFT_RENAMING_ITEM_OBJECT");
                return;
            }

            string crafterPlayerID = renameItem.GetLocalString("CRAFTER_PLAYER_ID");

            if (string.IsNullOrWhiteSpace(crafterPlayerID) || new Guid(crafterPlayerID) != pc.GlobalID)
            {
                pc.SendMessage("You may only rename items which you have personally crafted.");
                return;
            }

            SetLocalBool(pc, "CRAFT_RENAMING_ITEM", true);
            pc.SetLocalObject("CRAFT_RENAMING_ITEM_OBJECT", renameItem);
            pc.SendMessage("Please enter in a name for this item. Length should be between 3 and 64 characters. Use this feat again to cancel this procedure.");
        }
Beispiel #5
0
        public bool Run(params object[] args)
        {
            NWPlaceable plc           = NWPlaceable.Wrap(Object.OBJECT_SELF);
            NWPlayer    oPC           = NWPlayer.Wrap(_.GetLastAttacker());
            NWItem      oWeapon       = NWItem.Wrap(_.GetLastWeaponUsed(oPC.Object));
            int         type          = oWeapon.BaseItemType;
            int         resourceCount = plc.GetLocalInt("RESOURCE_COUNT");

            if (resourceCount <= -1)
            {
                resourceCount = _random.Random(3) + 3;
                plc.SetLocalInt("RESOURCE_COUNT", resourceCount);
            }

            if (type == BASE_ITEM_INVALID)
            {
                oWeapon = oPC.RightHand;
            }

            int activityID = plc.GetLocalInt("RESOURCE_ACTIVITY");

            string improperWeaponMessage = "";
            bool   usingCorrectWeapon    = true;

            if (activityID == 1) // 1 = Logging
            {
                usingCorrectWeapon = oWeapon.CustomItemType == CustomItemType.Blade ||
                                     oWeapon.CustomItemType == CustomItemType.TwinBlade ||
                                     oWeapon.CustomItemType == CustomItemType.HeavyBlade ||
                                     oWeapon.CustomItemType == CustomItemType.FinesseBlade ||
                                     oWeapon.CustomItemType == CustomItemType.Polearm;
                improperWeaponMessage = "You must be using a blade to harvest this object.";
            }
            else if (activityID == 2) // Mining
            {
                usingCorrectWeapon = oWeapon.CustomItemType == CustomItemType.Blade ||
                                     oWeapon.CustomItemType == CustomItemType.TwinBlade ||
                                     oWeapon.CustomItemType == CustomItemType.HeavyBlade ||
                                     oWeapon.CustomItemType == CustomItemType.FinesseBlade ||
                                     oWeapon.CustomItemType == CustomItemType.Polearm ||
                                     oWeapon.CustomItemType == CustomItemType.Blunt ||
                                     oWeapon.CustomItemType == CustomItemType.HeavyBlunt;
                improperWeaponMessage = "You must be using a blade or a blunt weapon to harvest this object.";
            }

            if (!usingCorrectWeapon)
            {
                plc.IsPlot = true;
                oPC.SendMessage(_color.Red(improperWeaponMessage));
                oPC.SetLocalInt("NOT_USING_CORRECT_WEAPON", 1);
                oPC.ClearAllActions();
                oPC.DelayCommand(() => plc.IsPlot = false, 1.0f);
            }

            return(true);
        }
Beispiel #6
0
        private static void OnModuleUseFeat()
        {
            NWPlayer pc     = (Object.OBJECT_SELF);
            int      featID = NWNXEvents.OnFeatUsed_GetFeatID();

            if (featID != (int)CustomFeatType.OpenRestMenu)
            {
                return;
            }
            pc.ClearAllActions();
            DialogService.StartConversation(pc, pc, "RestMenu");
        }
Beispiel #7
0
        public void OnModuleUseFeat()
        {
            NWPlayer pc     = NWPlayer.Wrap(Object.OBJECT_SELF);
            int      featID = _nwnxEvents.OnFeatUsed_GetFeatID();

            if (featID != (int)CustomFeatType.OpenRestMenu)
            {
                return;
            }
            pc.ClearAllActions();
            _dialog.StartConversation(pc, pc, "RestMenu");
        }
Beispiel #8
0
        private static void OnModuleUseFeat()
        {
            NWPlayer pc     = (OBJECT_SELF);
            int      featID = Convert.ToInt32(NWNXEvents.GetEventData("FEAT_ID"));

            if (featID != (int)Feat.OpenRestMenu)
            {
                return;
            }
            pc.ClearAllActions();
            DialogService.StartConversation(pc, pc, "RestMenu");
        }
        private void ForceEquipFistGlove(NWPlayer oPC)
        {
            _.DelayCommand(1.0f, () =>
            {
                if (!oPC.Arms.IsValid)
                {
                    oPC.ClearAllActions();
                    NWItem glove = (_.CreateItemOnObject("fist", oPC.Object));
                    glove.SetLocalInt("UNBREAKABLE", 1);

                    oPC.AssignCommand(() => _.ActionEquipItem(glove.Object, INVENTORY_SLOT_ARMS));
                }
            });
        }
Beispiel #10
0
        public bool IsPVPAttackAllowed(NWPlayer attacker, NWPlayer target)
        {
            // Check for sanctuary if this attack is PC versus PC
            if (target.IsPlayer && attacker.IsPlayer)
            {
                // Either the attacker or target has sanctuary - prevent combat from happening
                if (PlayerHasPVPSanctuary(attacker))
                {
                    attacker.FloatingText(_color.Red("You are under the effects of PVP sanctuary and cannot engage in PVP. To disable this feature permanently refer to the 'Disable PVP Sanctuary' option in your rest menu."));
                    attacker.DelayAssignCommand(() => attacker.ClearAllActions(), 0.0f);

                    return(false);
                }
                else if (PlayerHasPVPSanctuary(target))
                {
                    attacker.FloatingText(_color.Red("Your target is under the effects of PVP sanctuary and cannot engage in PVP combat."));
                    attacker.DelayAssignCommand(() => attacker.ClearAllActions(), 0.0f);
                    return(false);
                }
            }

            return(true);
        }
Beispiel #11
0
        public bool Run(params object[] args)
        {
            NWPlayer    clicker = (_.GetPlaceableLastClickedBy());
            NWPlaceable tower   = (Object.OBJECT_SELF);

            clicker.ClearAllActions();
            if (!clicker.IsPlayer)
            {
                return(false);
            }

            // Check the distance.
            if (_.GetDistanceBetween(clicker.Object, tower.Object) > 15.0f)
            {
                clicker.SendMessage("You are too far away to interact with that control tower.");
                return(false);
            }
            Guid            structureID = new Guid(tower.GetLocalString("PC_BASE_STRUCTURE_ID"));
            PCBaseStructure structure   = DataService.Single <PCBaseStructure>(x => x.ID == structureID);

            // Does the player have permission to access the fuel bays?
            if (BasePermissionService.HasBasePermission(clicker, structure.PCBaseID, BasePermission.CanManageBaseFuel))
            {
                // Is the tower in reinforced mode? If so, fuel cannot be accessed.
                var pcBase = DataService.Single <PCBase>(x => x.ID == structure.PCBaseID);
                if (pcBase.IsInReinforcedMode)
                {
                    clicker.SendMessage("This tower is currently in reinforced mode and cannot be accessed.");
                }
                else
                {
                    DialogService.StartConversation(clicker, tower, "ControlTower");
                }
            }
            else
            {
                clicker.SendMessage("You don't have permission to interact with this control tower.");
            }

            return(true);
        }
Beispiel #12
0
        public void OnModuleUseFeat()
        {
            NWPlayer   player         = (Object.OBJECT_SELF);
            int        featID         = _nwnxEvents.OnFeatUsed_GetFeatID();
            NWLocation targetLocation = _nwnxEvents.OnFeatUsed_GetTargetLocation();
            NWArea     targetArea     = (_.GetAreaFromLocation(targetLocation));

            if (featID != (int)CustomFeatType.StructureManagementTool)
            {
                return;
            }

            var data = GetPlayerTempData(player);

            data.TargetArea     = targetArea;
            data.TargetLocation = targetLocation;
            data.TargetObject   = _nwnxEvents.OnItemUsed_GetTarget();

            player.ClearAllActions();
            _dialog.StartConversation(player, player, "BaseManagementTool");
        }
        // Players abuse a bug in NWN which allows them to gain an extra attack.
        // To work around this I force them to clear all actions. There is a short delay to
        // account for weapons like guns which auto-equip ammo.
        private void HandleEquipmentSwappingDelay()
        {
            NWPlayer oPC       = NWPlayer.Wrap(_.GetPCItemLastEquippedBy());
            NWItem   oItem     = NWItem.Wrap(_.GetPCItemLastEquipped());
            NWItem   rightHand = oPC.RightHand;
            NWItem   leftHand  = oPC.LeftHand;

            if (!oPC.IsInCombat)
            {
                return;
            }
            if (Equals(oItem, rightHand) && Equals(oItem, leftHand))
            {
                return;
            }
            if (!Equals(oItem, leftHand))
            {
                return;
            }

            oPC.ClearAllActions();
        }
Beispiel #14
0
        public static void ToggleDualPistolMode(NWPlayer oPC)
        {
            Player pc = DataService.Player.GetByID(oPC.GlobalID);

            pc.ModeDualPistol = !pc.ModeDualPistol;
            DataService.SubmitDataChange(pc, DatabaseActionType.Update);
            //Console.WriteLine("ToggleDualMode Changed To = " + pc.ModeDualPistol);

            NWItem oItem = GetItemInSlot(InventorySlot.RightHand);

            if (oItem.BaseItemType == BaseItem.ShortBow ||
                oItem.BaseItemType == BaseItem.Sling)
            {
                oPC.ClearAllActions();

                // This isn't working for some reason:
                oPC.AssignCommand(() =>
                {
                    ActionUnequipItem(oItem);
                    ActionEquipItem(oItem, InventorySlot.RightHand);
                });
            }
        }
Beispiel #15
0
        public void OnModuleActivatedItem()
        {
            NWPlayer user           = (_.GetItemActivator());
            NWItem   oItem          = (_.GetItemActivated());
            NWObject target         = (_.GetItemActivatedTarget());
            Location targetLocation = _.GetItemActivatedTargetLocation();

            string className = oItem.GetLocalString("JAVA_SCRIPT");

            if (string.IsNullOrWhiteSpace(className))
            {
                className = oItem.GetLocalString("ACTIVATE_JAVA_SCRIPT");
            }
            if (string.IsNullOrWhiteSpace(className))
            {
                className = oItem.GetLocalString("JAVA_ACTION_SCRIPT");
            }
            if (string.IsNullOrWhiteSpace(className))
            {
                className = oItem.GetLocalString("SCRIPT");
            }
            if (string.IsNullOrWhiteSpace(className))
            {
                return;
            }

            user.ClearAllActions();

            if (user.IsBusy)
            {
                user.SendMessage("You are busy.");
                return;
            }

            // Remove "Item." prefix if it exists.
            if (className.StartsWith("Item."))
            {
                className = className.Substring(5);
            }

            App.ResolveByInterface <IActionItem>("Item." + className, (item) =>
            {
                string invalidTargetMessage = item.IsValidTarget(user, oItem, target, targetLocation);
                if (!string.IsNullOrWhiteSpace(invalidTargetMessage))
                {
                    user.SendMessage(invalidTargetMessage);
                    return;
                }

                float maxDistance = item.MaxDistance(user, oItem, target, targetLocation);
                if (maxDistance > 0.0f)
                {
                    if (target.IsValid &&
                        (_.GetDistanceBetween(user.Object, target.Object) > maxDistance ||
                         user.Area.Resref != target.Area.Resref))
                    {
                        user.SendMessage("Your target is too far away.");
                        return;
                    }
                    else if (!target.IsValid &&
                             (_.GetDistanceBetweenLocations(user.Location, targetLocation) > maxDistance ||
                              user.Area.Resref != ((NWArea)_.GetAreaFromLocation(targetLocation)).Resref))
                    {
                        user.SendMessage("That location is too far away.");
                        return;
                    }
                }

                CustomData customData = item.StartUseItem(user, oItem, target, targetLocation);
                float delay           = item.Seconds(user, oItem, target, targetLocation, customData);
                int animationID       = item.AnimationID();
                bool faceTarget       = item.FaceTarget();
                Vector userPosition   = user.Position;

                user.AssignCommand(() =>
                {
                    user.IsBusy = true;
                    if (faceTarget)
                    {
                        _.SetFacingPoint(!target.IsValid ? _.GetPositionFromLocation(targetLocation) : target.Position);
                    }
                    if (animationID > 0)
                    {
                        _.ActionPlayAnimation(animationID, 1.0f, delay);
                    }
                });

                _nwnxPlayer.StartGuiTimingBar(user, delay, string.Empty);
                user.DelayEvent <FinishActionItem>(
                    delay,
                    className,
                    user,
                    oItem,
                    target,
                    targetLocation,
                    userPosition,
                    customData);
            });
        }
Beispiel #16
0
        public bool Run(params object[] args)
        {
            NWPlaceable oSite = NWPlaceable.Wrap(Object.OBJECT_SELF);
            NWPlayer    oPC   = NWPlayer.Wrap(_.GetLastAttacker(oSite.Object));
            int         constructionSiteID = _structure.GetConstructionSiteID(oSite);

            if (constructionSiteID <= 0)
            {
                oPC.FloatingText("You must select a blueprint before you can build.");
                oPC.ClearAllActions();
                return(true);
            }

            NWItem weapon     = NWItem.Wrap(_.GetLastWeaponUsed(oPC.Object));
            int    weaponType = weapon.BaseItemType;

            if (weaponType != BASE_ITEM_LIGHTHAMMER)
            {
                oPC.FloatingText("A hammer must be equipped to build this structure.");
                oPC.ClearAllActions();
                return(true);
            }

            // Offhand weapons don't contribute to building.
            if (weapon.Equals(oPC.LeftHand))
            {
                return(true);
            }

            if (!_structure.IsConstructionSiteValid(oSite))
            {
                oPC.FloatingText("Construction site is invalid. Please click the construction site to find out more.");
                oPC.ClearAllActions();
                return(true);
            }


            Data.Entities.ConstructionSite entity = _structure.GetConstructionSiteByID(constructionSiteID);


            if (weapon.CraftTierLevel < entity.StructureBlueprint.CraftTierLevel)
            {
                oPC.FloatingText("Your hammer cannot be used with this blueprint. (Required Tool Level: " + entity.StructureBlueprint.CraftTierLevel + ")");
                oPC.ClearAllActions();
                return(true);
            }

            int    rank          = _skill.GetPCSkill(oPC, SkillType.Construction).Rank;
            int    mangleChance  = CalculateMangleChance(oPC, entity.StructureBlueprint.Level, rank);
            bool   isMangle      = _random.Random(100) + 1 <= mangleChance;
            bool   foundResource = false;
            string updateMessage = "You lack the necessary resources...";

            int totalAmount = 0;

            foreach (ConstructionSiteComponent comp in entity.ConstructionSiteComponents)
            {
                if (comp.Quantity > 0 && !foundResource)
                {
                    NWItem item = NWItem.Wrap(_.GetItemPossessedBy(oPC.Object, comp.StructureComponent.Resref));
                    if (item.IsValid)
                    {
                        int reuseChance = isMangle ? 0 : _perk.GetPCPerkLevel(oPC, PerkType.ConservativeConstruction) * 2 + _perk.GetPCPerkLevel(oPC, PerkType.Lucky);
                        if (_random.Random(100) + 1 <= reuseChance)
                        {
                            oPC.SendMessage("You conserve a resource...");
                        }
                        else
                        {
                            item.ReduceItemStack();
                        }

                        if (isMangle)
                        {
                            oPC.SendMessage(_color.Red("You mangle a resource due to your lack of skill..."));
                            return(true);
                        }

                        string name = _item.GetNameByResref(comp.StructureComponent.Resref);
                        comp.Quantity--;
                        updateMessage = "You need " + comp.Quantity + " " + name + " to complete this project.";
                        foundResource = true;
                    }
                }
                totalAmount += comp.Quantity;
            }

            oPC.DelayCommand(() => oPC.SendMessage(updateMessage), 0.75f);

            if (totalAmount <= 0)
            {
                _structure.CompleteStructure(oSite);
            }
            else if (foundResource)
            {
                _structure.SaveChanges();
                _durability.RunItemDecay(oPC, weapon);

                if (entity.StructureBlueprint.GivesSkillXP)
                {
                    int xp = (int)_skill.CalculateSkillAdjustedXP(100, 0, rank);
                    _skill.GiveSkillXP(oPC, SkillType.Construction, xp);
                }

                // Speedy Builder - Grants haste for 8 seconds
                int hasteChance = _perk.GetPCPerkLevel(oPC, PerkType.SpeedyBuilder) * 10;

                if (hasteChance > 0)
                {
                    hasteChance += _perk.GetPCPerkLevel(oPC, PerkType.Lucky) * 2;
                }

                PlayerCharacter pcEntity = _player.GetPlayerEntity(oPC);
                if (pcEntity.BackgroundID == (int)BackgroundType.ConstructionBuilder)
                {
                    hasteChance += 10;
                }

                if (_random.Random(100) + 1 <= hasteChance)
                {
                    _.ApplyEffectToObject(DURATION_TYPE_TEMPORARY, _.EffectHaste(), oPC.Object, 8.0f);
                }
            }
            else
            {
                oPC.ClearAllActions();
            }
            return(true);
        }
Beispiel #17
0
        public void OnModuleActivatedItem()
        {
            NWPlayer oPC            = NWPlayer.Wrap(_.GetItemActivator());
            NWItem   oItem          = NWItem.Wrap(_.GetItemActivated());
            NWObject oTarget        = NWObject.Wrap(_.GetItemActivatedTarget());
            Location targetLocation = _.GetItemActivatedTargetLocation();

            string className = oItem.GetLocalString("JAVA_SCRIPT");

            if (className == string.Empty)
            {
                className = oItem.GetLocalString("ACTIVATE_JAVA_SCRIPT");
            }
            if (className == string.Empty)
            {
                className = oItem.GetLocalString("JAVA_ACTION_SCRIPT");
            }
            if (className == string.Empty)
            {
                className = oItem.GetLocalString("SCRIPT");
            }
            if (className == string.Empty)
            {
                return;
            }

            oPC.ClearAllActions();

            // Remove "Item." prefix if it exists.
            if (className.StartsWith("Item."))
            {
                className = className.Substring(5);
            }

            IActionItem item = App.ResolveByInterface <IActionItem>("Item." + className);

            if (oPC.IsBusy)
            {
                oPC.SendMessage("You are busy.");
                return;
            }

            string invalidTargetMessage = item.IsValidTarget(oPC, oItem, oTarget, targetLocation);

            if (!string.IsNullOrWhiteSpace(invalidTargetMessage))
            {
                oPC.SendMessage(invalidTargetMessage);
                return;
            }

            if (item.MaxDistance() > 0.0f)
            {
                if (_.GetDistanceBetween(oPC.Object, oTarget.Object) > item.MaxDistance() ||
                    oPC.Area.Resref != oTarget.Area.Resref)
                {
                    oPC.SendMessage("Your target is too far away.");
                    return;
                }
            }

            CustomData customData   = item.StartUseItem(oPC, oItem, oTarget, targetLocation);
            float      delay        = item.Seconds(oPC, oItem, oTarget, targetLocation, customData);
            int        animationID  = item.AnimationID();
            bool       faceTarget   = item.FaceTarget();
            Vector     userPosition = oPC.Position;

            oPC.AssignCommand(() =>
            {
                oPC.IsBusy = true;
                if (faceTarget)
                {
                    _.SetFacingPoint(oTarget.Position);
                }
                if (animationID > 0)
                {
                    _.ActionPlayAnimation(animationID, 1.0f, delay);
                }
            });

            _nwnxPlayer.StartGuiTimingBar(oPC, delay, string.Empty);
            oPC.DelayCommand(() =>
            {
                FinishActionItem(item, oPC, oItem, oTarget, targetLocation, userPosition, customData);
            }, delay);
        }
Beispiel #18
0
        private static void OnModuleChat()
        {
            NWPlayer sender     = GetPCChatSpeaker();
            var      talkvolume = GetPCChatVolume();

            /*
             * ChatChannelType channel = (ChatChannelType)NWNXChat.GetChannel();
             *
             * if (!IsInCall(sender)) return;
             * if (channel != ChatChannelType.PlayerTalk) return;
             * if (channel != ChatChannelType.PlayerWhisper) return;
             * if (channel != ChatChannelType.PlayerParty) return;
             */

            if (talkvolume == TalkVolume.Shout)
            {
                return;
            }
            if (talkvolume == TalkVolume.Tell)
            {
                return;
            }
            if (talkvolume == TalkVolume.SilentShout)
            {
                return;
            }
            if (talkvolume == TalkVolume.SilentTalk)
            {
                return;
            }

            NWPlayer receiver = GetHoloGram(sender);

            string text = _.GetPCChatMessage().Trim();

            if (text.StartsWith("/"))
            {
                return;
            }

            var animation = Animation.LoopingTalkNormal;

            if (text.Contains("!"))
            {
                animation = Animation.LoopingTalkForceful;
            }
            if (text.Contains("?"))
            {
                animation = Animation.LoopingTalkPleading;
            }

            SetCommandable(true, receiver);
            receiver.ClearAllActions();

            receiver.AssignCommand(() =>
            {
                ActionPlayAnimation(animation);
            });

            receiver.DelayAssignCommand(() =>
            {
                ActionSpeakString(text, talkvolume);
            }, 0.3f);
        }
Beispiel #19
0
        private static void OnItemUsed()
        {
            NWPlayer user            = _.OBJECT_SELF;
            NWItem   oItem           = _.StringToObject(NWNXEvents.GetEventData("ITEM_OBJECT_ID"));
            NWObject target          = _.StringToObject(NWNXEvents.GetEventData("TARGET_OBJECT_ID"));
            var      targetPositionX = (float)Convert.ToDouble(NWNXEvents.GetEventData("TARGET_POSITION_X"));
            var      targetPositionY = (float)Convert.ToDouble(NWNXEvents.GetEventData("TARGET_POSITION_Y"));
            var      targetPositionZ = (float)Convert.ToDouble(NWNXEvents.GetEventData("TARGET_POSITION_Z"));
            var      targetPosition  = Vector3(targetPositionX, targetPositionY, targetPositionZ);
            Location targetLocation  = Location(user.Area, targetPosition, 0.0f);

            string className = oItem.GetLocalString("SCRIPT");

            if (string.IsNullOrWhiteSpace(className))
            {
                className = oItem.GetLocalString("ACTIVATE_SCRIPT");
            }
            if (string.IsNullOrWhiteSpace(className))
            {
                className = oItem.GetLocalString("ACTION_SCRIPT");
            }
            if (string.IsNullOrWhiteSpace(className))
            {
                className = oItem.GetLocalString("SCRIPT");
            }
            // Legacy events follow. We can't remove these because of backwards compatibility issues with existing items.
            if (string.IsNullOrWhiteSpace(className))
            {
                className = oItem.GetLocalString("JAVA_SCRIPT");
            }
            if (string.IsNullOrWhiteSpace(className))
            {
                className = oItem.GetLocalString("ACTIVATE_JAVA_SCRIPT");
            }
            if (string.IsNullOrWhiteSpace(className))
            {
                className = oItem.GetLocalString("JAVA_ACTION_SCRIPT");
            }
            if (string.IsNullOrWhiteSpace(className))
            {
                return;
            }

            // Bypass the NWN "item use" animation.
            NWNXEvents.SkipEvent();

            user.ClearAllActions();

            if (user.IsBusy)
            {
                user.SendMessage("You are busy.");
                return;
            }

            // Remove "Item." prefix if it exists.
            if (className.StartsWith("Item."))
            {
                className = className.Substring(5);
            }
            IActionItem item = GetActionItemHandler(className);

            string invalidTargetMessage = item.IsValidTarget(user, oItem, target, targetLocation);

            if (!string.IsNullOrWhiteSpace(invalidTargetMessage))
            {
                user.SendMessage(invalidTargetMessage);
                return;
            }

            // NOTE - these checks are duplicated in FinishActionItem.  Keep both in sync.
            float maxDistance = item.MaxDistance(user, oItem, target, targetLocation);

            if (maxDistance > 0.0f)
            {
                NWObject owner = GetItemPossessor(target);

                if (target.IsValid && owner.IsValid)
                {
                    // We are okay - we have targeted an item in our inventory (we can't target someone
                    // else's inventory, so no need to actually check distance).
                }
                else if (target.Object == _.OBJECT_SELF)
                {
                    // Also okay.
                }
                else if (target.IsValid &&
                         (GetDistanceBetween(user.Object, target.Object) > maxDistance ||
                          user.Area.Resref != target.Area.Resref))
                {
                    user.SendMessage("Your target is too far away.");
                    return;
                }
                else if (!target.IsValid &&
                         (GetDistanceBetweenLocations(user.Location, targetLocation) > maxDistance ||
                          user.Area.Resref != ((NWArea)GetAreaFromLocation(targetLocation)).Resref))
                {
                    user.SendMessage("That location is too far away.");
                    return;
                }
            }

            CustomData customData   = item.StartUseItem(user, oItem, target, targetLocation);
            float      delay        = item.Seconds(user, oItem, target, targetLocation, customData);
            var        animationID  = item.AnimationID();
            bool       faceTarget   = item.FaceTarget();
            Vector3    userPosition = user.Position;

            user.AssignCommand(() =>
            {
                user.IsBusy = true;
                if (faceTarget)
                {
                    SetFacingPoint(!target.IsValid ? GetPositionFromLocation(targetLocation) : target.Position);
                }
                if (animationID > 0)
                {
                    ActionPlayAnimation(animationID, 1.0f, delay);
                }
            });

            if (delay > 0.0f)
            {
                NWNXPlayer.StartGuiTimingBar(user, delay, string.Empty);
            }

            var @event = new OnFinishActionItem(className, user, oItem, target, targetLocation, userPosition, customData);

            user.DelayEvent(delay, @event);
        }