Ejemplo n.º 1
0
        private void CheckForSpellInterruption(NWPlayer pc, string spellUUID, Vector position)
        {
            if (pc.GetLocalInt(spellUUID) == (int)SpellStatusType.Completed)
            {
                return;
            }

            Vector currentPosition = pc.Position;

            if (currentPosition.m_X != position.m_X ||
                currentPosition.m_Y != position.m_Y ||
                currentPosition.m_Z != position.m_Z)
            {
                var effect = pc.Effects.SingleOrDefault(x => _.GetEffectTag(x) == "ACTIVATION_VFX");
                if (effect != null)
                {
                    _.RemoveEffect(pc, effect);
                }

                _nwnxPlayer.StopGuiTimingBar(pc, "", -1);
                pc.IsBusy = false;
                pc.SetLocalInt(spellUUID, (int)SpellStatusType.Interrupted);
                pc.SendMessage("Your ability has been interrupted.");
                return;
            }

            _.DelayCommand(0.5f, () => { CheckForSpellInterruption(pc, spellUUID, position); });
        }
Ejemplo n.º 2
0
        public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData)
        {
            NWPlayer player           = user.Object;
            int      ability          = item.GetLocalInt("ABILITY_TYPE");
            int      amount           = item.GetLocalInt("AMOUNT") + item.MedicineBonus;
            int      rank             = player.IsPlayer ? _skill.GetPCSkillRank(player, SkillType.Medicine) : 0;
            int      recommendedLevel = item.RecommendedLevel;
            float    duration         = 30.0f;
            int      perkLevel        = player.IsPlayer ? _perk.GetPCPerkLevel(player, PerkType.StimFiend) : 0;
            float    percentIncrease  = perkLevel * 0.25f;

            duration = duration + (duration * percentIncrease);
            Effect effect = _.EffectAbilityIncrease(ability, amount);

            effect = _.TagEffect(effect, "STIM_PACK_EFFECT");

            _.ApplyEffectToObject(NWScript.DURATION_TYPE_TEMPORARY, effect, target, duration);

            user.SendMessage("You inject " + target.Name + " with a stim pack. The stim pack will expire in " + duration + " seconds.");

            _.DelayCommand(duration + 0.5f, () => { player.SendMessage("The stim pack that you applied to " + target.Name + " has expired."); });

            if (!Equals(user, target))
            {
                NWCreature targetCreature = target.Object;
                targetCreature.SendMessage(user.Name + " injects you with a stim pack.");
            }

            int xp = (int)_skill.CalculateRegisteredSkillLevelAdjustedXP(300, item.RecommendedLevel, rank);

            _skill.GiveSkillXP(player, SkillType.Medicine, xp);
        }
Ejemplo n.º 3
0
        public bool Run(params object[] args)
        {
            NWObject door = Object.OBJECT_SELF;

            if (!door.Area.IsInstance)
            {
                return(false);
            }

            NWObject target = _.GetTransitionTarget(door);
            NWPlayer player = _.GetClickingObject();

            _.DelayCommand(6.0f, () =>
            {
                int playerCount = NWModule.Get().Players.Count(x => !Equals(x, player) && Equals(x.Area, door.Area));
                if (playerCount <= 0)
                {
                    _area.DestroyAreaInstance(door.Area);
                }
            });

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

            return(true);
        }
Ejemplo n.º 4
0
        public void OnPlayerRespawn()
        {
            NWPlayer oPC = _.GetLastRespawnButtonPresser();

            int amount = oPC.MaxHP / 2;

            _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectResurrection(), oPC.Object);
            _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectHeal(amount), oPC.Object);

            NWArea area = oPC.Area;

            TeleportPlayerToBindPoint(oPC);

            // If player is the last person in an instance, destroy the instance.
            if (area.IsInstance)
            {
                int playersInArea = NWModule.Get().Players.Count(x => x.Area == oPC.Area && x != oPC);

                if (playersInArea <= 0)
                {
                    _.DelayCommand(12.0f, () =>
                    {
                        _area.DestroyAreaInstance(area);
                    });
                }
            }
        }
Ejemplo n.º 5
0
        private void RunProcessor()
        {
            foreach (var toUnregister in _cache.UnregisterProcessingEvents)
            {
                _cache.ProcessingEvents.Remove(toUnregister);
            }
            _cache.UnregisterProcessingEvents.Clear();

            foreach (var @event in _cache.ProcessingEvents)
            {
                try
                {
                    App.ResolveByInterface <IEventProcessor>(@event.Value.ProcessorType.ToString(), (processor) =>
                    {
                        processor.Run(@event.Value.Args);
                    });
                }
                catch (Exception ex)
                {
                    _error.LogError(ex, "ObjectProcessingService. EventID = " + @event.Key);
                }
            }

            _.DelayCommand(ProcessingTickInterval, RunProcessor);
        }
Ejemplo n.º 6
0
        private void RunProcessor()
        {
            foreach (var @event in _state.ProcessingEvents)
            {
                @event.Value.Invoke();
            }

            _.DelayCommand(ProcessingTickInterval, RunProcessor);
        }
Ejemplo n.º 7
0
        public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData)
        {
            NWPlayer player         = (user.Object);
            var      effectiveStats = _playerStat.GetPlayerItemEffectiveStats(player);

            target.RemoveEffect(EFFECT_TYPE_REGENERATE);
            int   rank = _skill.GetPCSkillRank(player, SkillType.Medicine);
            int   luck = _perk.GetPCPerkLevel(player, PerkType.Lucky);
            int   perkDurationBonus    = _perk.GetPCPerkLevel(player, PerkType.HealingKitExpert) * 6 + (luck * 2);
            float duration             = 30.0f + (rank * 0.4f) + perkDurationBonus;
            int   restoreAmount        = 1 + item.GetLocalInt("HEALING_BONUS") + effectiveStats.Medicine + item.MedicineBonus;
            int   delta                = item.RecommendedLevel - rank;
            float effectivenessPercent = 1.0f;

            if (delta > 0)
            {
                effectivenessPercent = effectivenessPercent - (delta * 0.1f);
            }

            restoreAmount = (int)(restoreAmount * effectivenessPercent);

            int perkBlastBonus = _perk.GetPCPerkLevel(player, PerkType.ImmediateImprovement);

            if (perkBlastBonus > 0)
            {
                int blastHeal = restoreAmount * perkBlastBonus;
                if (_random.Random(100) + 1 <= luck / 2)
                {
                    blastHeal *= 2;
                }
                _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectHeal(blastHeal), target.Object);
            }

            float          interval   = 6.0f;
            BackgroundType background = (BackgroundType)player.Class1;

            if (background == BackgroundType.Medic)
            {
                interval *= 0.5f;
            }

            Effect regeneration = _.EffectRegenerate(restoreAmount, interval);

            _.ApplyEffectToObject(DURATION_TYPE_TEMPORARY, regeneration, target.Object, duration);
            player.SendMessage("You successfully treat " + target.Name + "'s wounds. The healing kit will expire in " + duration + " seconds.");

            _.DelayCommand(duration + 0.5f, () => { player.SendMessage("The healing kit that you applied to " + target.Name + " has expired."); });

            if (target.IsPlayer)
            {
                int xp = (int)_skill.CalculateRegisteredSkillLevelAdjustedXP(300, item.RecommendedLevel, rank);
                _skill.GiveSkillXP(player, SkillType.Medicine, xp);
            }
        }
Ejemplo n.º 8
0
        public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData)
        {
            NWPlayer player               = (user.Object);
            var      effectiveStats       = _playerStat.GetPlayerItemEffectiveStats(player);
            int      rank                 = _skill.GetPCSkillRank(player, SkillType.Medicine);
            int      luck                 = _perk.GetPCPerkLevel(player, PerkType.Lucky);
            int      perkDurationBonus    = _perk.GetPCPerkLevel(player, PerkType.HealingKitExpert) * 6 + (luck * 2);
            float    duration             = 30.0f + (rank * 0.4f) + perkDurationBonus;
            int      restoreAmount        = 1 + item.GetLocalInt("HEALING_BONUS") + effectiveStats.Medicine + item.MedicineBonus;
            int      delta                = item.RecommendedLevel - rank;
            float    effectivenessPercent = 1.0f;

            if (delta > 0)
            {
                effectivenessPercent = effectivenessPercent - (delta * 0.1f);
            }

            restoreAmount = (int)(restoreAmount * effectivenessPercent);

            int perkBlastBonus = _perk.GetPCPerkLevel(player, PerkType.ImmediateForcePack);

            if (perkBlastBonus > 0)
            {
                int blastHeal = restoreAmount * perkBlastBonus;
                if (_random.Random(100) + 1 <= luck / 2)
                {
                    blastHeal *= 2;
                }

                _ability.RestoreFP(target.Object, blastHeal);
            }

            float          interval   = 6.0f;
            BackgroundType background = (BackgroundType)player.Class1;

            if (background == BackgroundType.Medic)
            {
                interval *= 0.5f;
            }

            string data = (int)interval + ", " + restoreAmount;

            _customEffect.ApplyCustomEffect(user, target.Object, CustomEffectType.ForcePack, (int)duration, restoreAmount, data);

            player.SendMessage("You successfully apply a force pack to " + target.Name + ". The force pack will expire in " + duration + " seconds.");

            _.DelayCommand(duration + 0.5f, () => { player.SendMessage("The force pack that you applied to " + target.Name + " has expired."); });

            int xp = (int)_skill.CalculateRegisteredSkillLevelAdjustedXP(300, item.RecommendedLevel, rank);

            _skill.GiveSkillXP(player, SkillType.Medicine, xp);
        }
Ejemplo n.º 9
0
        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));
                }
            });
        }
Ejemplo n.º 10
0
        public void DoPlayerExitBuildingInstance(NWPlayer player, NWPlaceable door = null)
        {
            NWArea area = player.Area;

            if (!area.IsInstance)
            {
                return;
            }

            if (door == null)
            {
                NWObject obj = (_.GetFirstObjectInArea(area.Object));
                while (obj.IsValid)
                {
                    if (obj.Tag == "building_exit")
                    {
                        door = (obj.Object);
                        break;
                    }
                    obj = (_.GetNextObjectInArea(area.Object));
                }
            }

            if (door == null)
            {
                return;
            }

            Location location = door.GetLocalLocation("PLAYER_HOME_EXIT_LOCATION");

            player.AssignCommand(() => _.ActionJumpToLocation(location));

            _.DelayCommand(1.0f, () =>
            {
                player = (_.GetFirstPC());
                while (player.IsValid)
                {
                    if (Equals(player.Area, area))
                    {
                        return;
                    }
                    player = (_.GetNextPC());
                }

                _area.DestroyAreaInstance(area);
            });
        }
Ejemplo n.º 11
0
        public void CraftItem(NWPlayer oPC, NWPlaceable device)
        {
            var            model     = GetPlayerCraftingData(oPC);
            CraftBlueprint blueprint = _data.Single <CraftBlueprint>(x => x.ID == model.BlueprintID);

            if (blueprint == null)
            {
                return;
            }

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

            if (!model.CanBuildItem)
            {
                oPC.SendMessage("You are missing one or more components...");
                return;
            }

            oPC.IsBusy = true;

            int   atmosphere         = CalculateAreaAtmosphereBonus(oPC.Area);
            float modifiedCraftDelay = CalculateCraftingDelay(oPC, blueprint.SkillID, atmosphere);

            oPC.AssignCommand(() =>
            {
                _.ClearAllActions();
                _.ActionPlayAnimation(ANIMATION_LOOPING_GET_MID, 1.0f, modifiedCraftDelay);
            });
            _.DelayCommand(1.0f * (modifiedCraftDelay / 2.0f), () =>
            {
                _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectVisualEffect(VFX_COM_BLOOD_SPARK_MEDIUM), device.Object);
            });
            Effect immobilize = _.EffectCutsceneImmobilize();

            immobilize = _.TagEffect(immobilize, "CRAFTING_IMMOBILIZATION");
            _.ApplyEffectToObject(DURATION_TYPE_PERMANENT, immobilize, oPC.Object);

            _nwnxPlayer.StartGuiTimingBar(oPC, modifiedCraftDelay, "");

            oPC.DelayEvent <CraftCreateItem>(
                modifiedCraftDelay,
                oPC);
        }
Ejemplo n.º 12
0
        public void DoAction(NWPlayer user, NWObject target, NWLocation targetLocation, params string[] args)
        {
            string message = string.Empty;

            foreach (var arg in args)
            {
                message += " " + arg;
            }

            DiscordChatQueue chatRecord = new DiscordChatQueue
            {
                DateSent          = DateTime.UtcNow,
                Message           = message,
                SenderName        = user.Name,
                SenderAccountName = _.GetPCPlayerName(user),
                SenderCDKey       = _.GetPCPublicCDKey(user)
            };

            _data.SubmitDataChange(chatRecord, DatabaseActionType.Insert);

            _.DelayCommand(0.1f, () =>
            {
                NWObject chatSender = _.GetObjectByTag("Holonet");
                if (!chatSender.IsValid)
                {
                    return;
                }

                foreach (var player in NWModule.Get().Players)
                {
                    if (player.GetLocalInt("DISPLAY_DISCORD") == FALSE)
                    {
                        continue;
                    }

                    message = "[Discord] " + user.Name + ": " + message;
                    message = _color.Custom(message, 255, 218, 185);
                    _nwnxChat.SendMessage((int)ChatChannelType.PlayerTell, message, chatSender, user);
                }
            });
        }
        private void RunProcessor()
        {
            foreach (var toUnregister in _state.UnregisterProcessingEvents)
            {
                _state.ProcessingEvents.Remove(toUnregister);
            }
            _state.UnregisterProcessingEvents.Clear();

            foreach (var @event in _state.ProcessingEvents)
            {
                try
                {
                    @event.Value.Invoke();
                }
                catch (Exception ex)
                {
                    _error.LogError(ex, "ObjectProcessingService. EventID = " + @event.Key);
                }
            }

            _.DelayCommand(ProcessingTickInterval, RunProcessor);
        }
Ejemplo n.º 14
0
        public void InitializePlayer(NWPlayer player)
        {
            if (player == null)
            {
                throw new ArgumentNullException(nameof(player));
            }
            if (player.Object == null)
            {
                throw new ArgumentNullException(nameof(player.Object));
            }
            if (!player.IsPlayer)
            {
                return;
            }

            // Player is initialized but not in the DB. Wipe the tag and rerun them through initialization - something went wrong before.
            if (player.IsInitializedAsPlayer)
            {
                if (_data.GetAll <Player>().SingleOrDefault(x => x.ID == player.GlobalID) == null)
                {
                    _.SetTag(player, string.Empty);
                }
            }

            if (!player.IsInitializedAsPlayer)
            {
                player.DestroyAllInventoryItems();
                player.InitializePlayer();
                _.AssignCommand(player, () => _.TakeGoldFromCreature(_.GetGold(player), player, 1));

                _.DelayCommand(0.5f, () =>
                {
                    _.GiveGoldToCreature(player, 100);
                });

                // Capture original stats before we level up the player.
                int str  = _nwnxCreature.GetRawAbilityScore(player, ABILITY_STRENGTH);
                int con  = _nwnxCreature.GetRawAbilityScore(player, ABILITY_CONSTITUTION);
                int dex  = _nwnxCreature.GetRawAbilityScore(player, ABILITY_DEXTERITY);
                int @int = _nwnxCreature.GetRawAbilityScore(player, ABILITY_INTELLIGENCE);
                int wis  = _nwnxCreature.GetRawAbilityScore(player, ABILITY_WISDOM);
                int cha  = _nwnxCreature.GetRawAbilityScore(player, ABILITY_CHARISMA);

                // Take player to level 5 in NWN levels so that we have access to more HP slots
                _.GiveXPToCreature(player, 10000);

                for (int level = 1; level <= 5; level++)
                {
                    _.LevelUpHenchman(player, player.Class1);
                }

                // Set stats back to how they were on entry.
                _nwnxCreature.SetRawAbilityScore(player, ABILITY_STRENGTH, str);
                _nwnxCreature.SetRawAbilityScore(player, ABILITY_CONSTITUTION, con);
                _nwnxCreature.SetRawAbilityScore(player, ABILITY_DEXTERITY, dex);
                _nwnxCreature.SetRawAbilityScore(player, ABILITY_INTELLIGENCE, @int);
                _nwnxCreature.SetRawAbilityScore(player, ABILITY_WISDOM, wis);
                _nwnxCreature.SetRawAbilityScore(player, ABILITY_CHARISMA, cha);

                NWItem knife = (_.CreateItemOnObject("survival_knife", player));
                knife.Name     = player.Name + "'s Survival Knife";
                knife.IsCursed = true;
                _durability.SetMaxDurability(knife, 5);
                _durability.SetDurability(knife, 5);

                NWItem book = (_.CreateItemOnObject("player_guide", player));
                book.Name     = player.Name + "'s Player Guide";
                book.IsCursed = true;

                NWItem dyeKit = (_.CreateItemOnObject("tk_omnidye", player));
                dyeKit.IsCursed = true;

                int numberOfFeats = _nwnxCreature.GetFeatCount(player);
                for (int currentFeat = numberOfFeats; currentFeat >= 0; currentFeat--)
                {
                    _nwnxCreature.RemoveFeat(player, _nwnxCreature.GetFeatByIndex(player, currentFeat - 1));
                }

                _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_LIGHT, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_MEDIUM, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_HEAVY, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_SHIELD_PROFICIENCY, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_EXOTIC, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_MARTIAL, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_SIMPLE, 1);
                _nwnxCreature.AddFeatByLevel(player, (int)CustomFeatType.StructureManagementTool, 1);
                _nwnxCreature.AddFeatByLevel(player, (int)CustomFeatType.OpenRestMenu, 1);
                _nwnxCreature.AddFeatByLevel(player, (int)CustomFeatType.RenameCraftedItem, 1);
                _nwnxCreature.AddFeatByLevel(player, (int)CustomFeatType.ChatCommandTargeter, 1);

                for (int iCurSkill = 1; iCurSkill <= 27; iCurSkill++)
                {
                    _nwnxCreature.SetSkillRank(player, iCurSkill - 1, 0);
                }
                _.SetFortitudeSavingThrow(player, 0);
                _.SetReflexSavingThrow(player, 0);
                _.SetWillSavingThrow(player, 0);

                int classID = _.GetClassByPosition(1, player);

                for (int index = 0; index <= 255; index++)
                {
                    _nwnxCreature.RemoveKnownSpell(player, classID, 0, index);
                }

                Player entity = CreateDBPCEntity(player);
                _data.SubmitDataChange(entity, DatabaseActionType.Insert);

                var skills = _data.GetAll <Skill>();
                foreach (var skill in skills)
                {
                    var pcSkill = new PCSkill
                    {
                        IsLocked = false,
                        SkillID  = skill.ID,
                        PlayerID = entity.ID,
                        Rank     = 0,
                        XP       = 0
                    };

                    _data.SubmitDataChange(pcSkill, DatabaseActionType.Insert);
                }

                _race.ApplyDefaultAppearance(player);
                _nwnxCreature.SetAlignmentLawChaos(player, 50);
                _nwnxCreature.SetAlignmentGoodEvil(player, 50);
                _background.ApplyBackgroundBonuses(player);

                _stat.ApplyStatChanges(player, null, true);
                _language.InitializePlayerLanguages(player);

                _.DelayCommand(1.0f, () => _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectHeal(999), player));

                InitializeHotBar(player);
            }
        }
Ejemplo n.º 15
0
        public void OnCreatureDeath(NWCreature creature)
        {
            int npcGroupID = creature.GetLocalInt("NPC_GROUP");

            if (npcGroupID <= 0)
            {
                return;
            }

            NWObject oKiller = _.GetLastKiller();

            if (!oKiller.IsPlayer)
            {
                return;
            }

            string areaResref = creature.Area.Resref;

            List <KeyValuePair <NWPlayer, int> > playersToAdvance = new List <KeyValuePair <NWPlayer, int> >();
            NWPlayer oPC = _.GetFirstFactionMember(oKiller);

            while (oPC.IsValid)
            {
                if (areaResref != oPC.Area.Resref)
                {
                    oPC = _.GetNextFactionMember(oKiller);
                    continue;
                }

                if (_.GetDistanceBetween(creature, oPC) <= 0.0f || _.GetDistanceBetween(creature, oPC) > 20.0f)
                {
                    oPC = _.GetNextFactionMember(oKiller);
                    continue;
                }

                var playerID    = oPC.GlobalID;
                var killTargets = _data.Where <PCQuestKillTargetProgress>(x => x.PlayerID == playerID && x.NPCGroupID == npcGroupID).ToList();

                foreach (var kt in killTargets)
                {
                    var questStatus = _data.Get <PCQuestStatus>(kt.PCQuestStatusID);
                    var quest       = _data.Get <Quest>(questStatus.QuestID);
                    var npcGroup    = _data.Get <NPCGroup>(kt.NPCGroupID);

                    kt.RemainingToKill--;
                    string             targetGroupName = npcGroup.Name;
                    string             updateMessage   = "[" + quest.Name + "] " + targetGroupName + " remaining: " + kt.RemainingToKill;
                    DatabaseActionType action          = DatabaseActionType.Update;

                    if (kt.RemainingToKill <= 0)
                    {
                        updateMessage += " " + _color.Green(" {COMPLETE}");
                        playersToAdvance.Add(new KeyValuePair <NWPlayer, int>(oPC, quest.ID));
                        action = DatabaseActionType.Delete;
                    }

                    _data.SubmitDataChange(kt, action);

                    var pc = oPC;
                    _.DelayCommand(1.0f, () =>
                    {
                        pc.SendMessage(updateMessage);
                    });

                    string ruleName = quest.OnKillTargetRule;
                    if (!string.IsNullOrWhiteSpace(ruleName))
                    {
                        var pcCopy = oPC;
                        App.ResolveByInterface <IQuestRule>("QuestRule." + ruleName, (rule) =>
                        {
                            string[] args = null;
                            if (!string.IsNullOrWhiteSpace(quest.OnKillTargetArgs))
                            {
                                args = quest.OnKillTargetArgs.Split(',');
                            }
                            rule.Run(pcCopy, creature, quest.ID, args);
                        });
                    }
                }

                oPC = _.GetNextFactionMember(oKiller);
            }

            foreach (var player in playersToAdvance)
            {
                AdvanceQuestState(player.Key, null, player.Value);
            }
        }
Ejemplo n.º 16
0
        public void OnCreatureDeath()
        {
            _.SetIsDestroyable(FALSE);

            NWObject self          = Object.OBJECT_SELF;
            Vector   lootPosition  = _.Vector(self.Position.m_X, self.Position.m_Y, self.Position.m_Z - 0.11f);
            Location spawnLocation = _.Location(self.Area, lootPosition, self.Facing);

            NWPlaceable container = _.CreateObject(OBJECT_TYPE_PLACEABLE, "corpse", spawnLocation);

            container.SetLocalObject("CORPSE_BODY", self);
            container.Name = self.Name + "'s Corpse";

            container.AssignCommand(() =>
            {
                _.TakeGoldFromCreature(self.Gold, self);
            });

            // Dump equipped items in container
            for (int slot = 0; slot < NUM_INVENTORY_SLOTS; slot++)
            {
                if (slot == INVENTORY_SLOT_CARMOUR ||
                    slot == INVENTORY_SLOT_CWEAPON_B ||
                    slot == INVENTORY_SLOT_CWEAPON_L ||
                    slot == INVENTORY_SLOT_CWEAPON_R)
                {
                    continue;
                }

                NWItem item = _.GetItemInSlot(slot, self);
                if (item.IsValid && !item.IsCursed && item.IsDroppable)
                {
                    NWItem copy = _.CopyItem(item, container, TRUE);

                    if (slot == INVENTORY_SLOT_HEAD ||
                        slot == INVENTORY_SLOT_CHEST)
                    {
                        copy.SetLocalObject("CORPSE_ITEM_COPY", item);
                    }
                    else
                    {
                        item.Destroy();
                    }
                }
            }

            foreach (var item in self.InventoryItems)
            {
                _.CopyItem(item, container, TRUE);
                item.Destroy();
            }

            _.DelayCommand(360.0f, () =>
            {
                if (!container.IsValid)
                {
                    return;
                }

                NWObject body = container.GetLocalObject("CORPSE_BODY");
                body.AssignCommand(() => _.SetIsDestroyable(TRUE));
                body.DestroyAllInventoryItems();
                body.Destroy();

                container.DestroyAllInventoryItems();
                container.Destroy();
            });
        }
Ejemplo n.º 17
0
        public void InitializeAreaSpawns(NWArea area)
        {
            var areaSpawn = new AreaSpawn();

            // Check for manually placed spawns
            NWObject obj = _.GetFirstObjectInArea(area.Object);

            while (obj.IsValid)
            {
                bool isSpawn = obj.ObjectType == OBJECT_TYPE_WAYPOINT && obj.GetLocalInt("IS_SPAWN") == TRUE;

                if (isSpawn)
                {
                    int    spawnType       = obj.GetLocalInt("SPAWN_TYPE");
                    int    objectType      = spawnType == 0 || spawnType == OBJECT_TYPE_CREATURE ? OBJECT_TYPE_CREATURE : spawnType;
                    int    spawnTableID    = obj.GetLocalInt("SPAWN_TABLE_ID");
                    int    npcGroupID      = obj.GetLocalInt("SPAWN_NPC_GROUP_ID");
                    string behaviourScript = obj.GetLocalString("SPAWN_BEHAVIOUR_SCRIPT");
                    string spawnResref     = obj.GetLocalString("SPAWN_RESREF");
                    float  respawnTime     = obj.GetLocalFloat("SPAWN_RESPAWN_SECONDS");
                    string spawnRule       = obj.GetLocalString("SPAWN_RULE");
                    int    deathVFXID      = obj.GetLocalInt("SPAWN_DEATH_VFX");
                    bool   useResref       = true;

                    // No resref specified but a table was, look in the database for a random record.
                    if (string.IsNullOrWhiteSpace(spawnResref) && spawnTableID > 0)
                    {
                        // Pick a random record.
                        var spawnObjects = _data.Where <SpawnObject>(x => x.SpawnID == spawnTableID).ToList();
                        int count        = spawnObjects.Count;
                        int index        = count <= 0 ? 0 : _random.Random(count);
                        var dbSpawn      = spawnObjects[index];

                        if (dbSpawn != null)
                        {
                            spawnResref = dbSpawn.Resref;
                            useResref   = false;

                            if (dbSpawn.NPCGroupID != null && dbSpawn.NPCGroupID > 0)
                            {
                                npcGroupID = Convert.ToInt32(dbSpawn.NPCGroupID);
                            }

                            if (!string.IsNullOrWhiteSpace(dbSpawn.BehaviourScript))
                            {
                                behaviourScript = dbSpawn.BehaviourScript;
                            }

                            if (!string.IsNullOrWhiteSpace(spawnRule))
                            {
                                spawnRule = dbSpawn.SpawnRule;
                            }

                            if (deathVFXID <= 0)
                            {
                                deathVFXID = dbSpawn.DeathVFXID;
                            }
                        }
                    }

                    // If we found a resref, spawn the object and add it to the cache.
                    if (!string.IsNullOrWhiteSpace(spawnResref))
                    {
                        // Delay the creation so that the iteration through the area doesn't get thrown off by new entries.
                        Location location   = obj.Location;
                        bool     isInstance = area.IsInstance;

                        ObjectSpawn newSpawn;
                        if (useResref)
                        {
                            newSpawn = new ObjectSpawn(location, true, spawnResref, respawnTime);
                        }
                        else
                        {
                            newSpawn = new ObjectSpawn(location, true, spawnTableID, respawnTime);
                        }

                        if (npcGroupID > 0)
                        {
                            newSpawn.NPCGroupID = npcGroupID;
                        }

                        if (deathVFXID > 0)
                        {
                            newSpawn.DeathVFXID = deathVFXID;
                        }

                        if (!string.IsNullOrWhiteSpace(behaviourScript))
                        {
                            newSpawn.BehaviourScript = behaviourScript;
                        }

                        if (!string.IsNullOrWhiteSpace(spawnRule))
                        {
                            newSpawn.SpawnRule = spawnRule;
                        }

                        // Instance spawns are one-shot.
                        if (isInstance)
                        {
                            newSpawn.Respawns = false;
                        }

                        if (objectType == OBJECT_TYPE_CREATURE)
                        {
                            areaSpawn.Creatures.Add(newSpawn);
                        }
                        else if (objectType == OBJECT_TYPE_PLACEABLE)
                        {
                            areaSpawn.Placeables.Add(newSpawn);
                        }
                    }
                }

                obj = _.GetNextObjectInArea(area.Object);
            }

            _cache.AreaSpawns.Add(area, areaSpawn);

            _.DelayCommand(1.0f, () =>
            {
                SpawnResources(area, areaSpawn);
            });
        }
Ejemplo n.º 18
0
        public void InitializePlayer(NWPlayer player)
        {
            if (player == null)
            {
                throw new ArgumentNullException(nameof(player));
            }
            if (player.Object == null)
            {
                throw new ArgumentNullException(nameof(player.Object));
            }

            if (!player.IsPlayer)
            {
                return;
            }

            if (!player.IsInitializedAsPlayer)
            {
                player.DestroyAllInventoryItems();
                player.InitializePlayer();

                _.CreateItemOnObject("open_rest_menu", player.Object);
                _.AssignCommand(player.Object, () => _.TakeGoldFromCreature(_.GetGold(player.Object), player.Object, 1));

                NWItem knife = NWItem.Wrap(_.CreateItemOnObject("survival_knife", player.Object));
                knife.Name          = player.Name + "'s Survival Knife";
                knife.IsCursed      = true;
                knife.MaxDurability = 5;
                knife.Durability    = 5;

                NWItem hammer = NWItem.Wrap(_.CreateItemOnObject("basic_hammer", player.Object));
                hammer.Name          = player.Name + "'s Hammer";
                hammer.IsCursed      = true;
                hammer.MaxDurability = 5;
                hammer.Durability    = 5;

                NWItem darts = NWItem.Wrap(_.CreateItemOnObject("nw_wthdt001", player.Object, 50)); // 50x Dart
                darts.Name     = "Starting Darts";
                darts.IsCursed = true;

                NWItem book = NWItem.Wrap(_.CreateItemOnObject("player_guide", player.Object));
                book.Name     = player.Name + "'s Player Guide";
                book.IsCursed = true;

                NWItem dyeKit = NWItem.Wrap(_.CreateItemOnObject("tk_omnidye", player.Object));
                dyeKit.IsCursed = true;

                NWItem shovel = NWItem.Wrap(_.CreateItemOnObject("basic_shovel", player.Object));
                shovel.Name     = player.Name + "'s Shovel";
                shovel.IsCursed = true;

                int numberOfFeats = _nwnxCreature.GetFeatCount(player);
                for (int currentFeat = numberOfFeats; currentFeat >= 0; currentFeat--)
                {
                    _nwnxCreature.RemoveFeat(player, _nwnxCreature.GetFeatByIndex(player, currentFeat - 1));
                }

                _nwnxCreature.SetClassByPosition(player, 0, CLASS_TYPE_FIGHTER);
                _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_LIGHT, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_MEDIUM, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_HEAVY, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_SHIELD_PROFICIENCY, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_EXOTIC, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_MARTIAL, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_SIMPLE, 1);

                for (int iCurSkill = 1; iCurSkill <= 27; iCurSkill++)
                {
                    _nwnxCreature.SetSkillRank(player, iCurSkill - 1, 0);
                }
                _.SetFortitudeSavingThrow(player.Object, 0);
                _.SetReflexSavingThrow(player.Object, 0);
                _.SetWillSavingThrow(player.Object, 0);

                int classID = _.GetClassByPosition(1, player.Object);

                for (int index = 0; index <= 255; index++)
                {
                    _nwnxCreature.RemoveKnownSpell(player, classID, 0, index);
                }

                using (DataContext context = new DataContext())
                {
                    PlayerCharacter entity = player.ToEntity();
                    context.PlayerCharacters.Add(entity);
                    context.SaveChanges();
                }

                _skill.ApplyStatChanges(player, null);

                _.DelayCommand(1000, () => _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectHeal(999), player.Object));

                InitializeHotBar(player);
            }
        }
Ejemplo n.º 19
0
        public void InitializePlayer(NWPlayer player)
        {
            if (player == null)
            {
                throw new ArgumentNullException(nameof(player));
            }
            if (player.Object == null)
            {
                throw new ArgumentNullException(nameof(player.Object));
            }
            if (!player.IsPlayer)
            {
                return;
            }

            if (!player.IsInitializedAsPlayer)
            {
                player.DestroyAllInventoryItems();
                player.InitializePlayer();
                _.AssignCommand(player.Object, () => _.TakeGoldFromCreature(_.GetGold(player.Object), player.Object, 1));

                player.DelayCommand(() =>
                {
                    _.GiveGoldToCreature(player.Object, 100);
                }, 0.5f);


                NWItem knife = NWItem.Wrap(_.CreateItemOnObject("survival_knife", player.Object));
                knife.Name          = player.Name + "'s Survival Knife";
                knife.IsCursed      = true;
                knife.MaxDurability = 5;
                knife.Durability    = 5;

                NWItem darts = NWItem.Wrap(_.CreateItemOnObject("nw_wthdt001", player.Object, 50)); // 50x Dart
                darts.Name     = "Starting Darts";
                darts.IsCursed = true;

                NWItem book = NWItem.Wrap(_.CreateItemOnObject("player_guide", player.Object));
                book.Name     = player.Name + "'s Player Guide";
                book.IsCursed = true;

                NWItem dyeKit = NWItem.Wrap(_.CreateItemOnObject("tk_omnidye", player.Object));
                dyeKit.IsCursed = true;

                int numberOfFeats = _nwnxCreature.GetFeatCount(player);
                for (int currentFeat = numberOfFeats; currentFeat >= 0; currentFeat--)
                {
                    _nwnxCreature.RemoveFeat(player, _nwnxCreature.GetFeatByIndex(player, currentFeat - 1));
                }

                _nwnxCreature.SetClassByPosition(player, 0, CLASS_TYPE_FIGHTER);
                _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_LIGHT, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_MEDIUM, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_HEAVY, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_SHIELD_PROFICIENCY, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_EXOTIC, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_MARTIAL, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_SIMPLE, 1);
                _nwnxCreature.AddFeatByLevel(player, (int)CustomFeatType.StructureTool, 1);
                _nwnxCreature.AddFeatByLevel(player, (int)CustomFeatType.OpenRestMenu, 1);

                for (int iCurSkill = 1; iCurSkill <= 27; iCurSkill++)
                {
                    _nwnxCreature.SetSkillRank(player, iCurSkill - 1, 0);
                }
                _.SetFortitudeSavingThrow(player.Object, 0);
                _.SetReflexSavingThrow(player.Object, 0);
                _.SetWillSavingThrow(player.Object, 0);

                int classID = _.GetClassByPosition(1, player.Object);

                for (int index = 0; index <= 255; index++)
                {
                    _nwnxCreature.RemoveKnownSpell(player, classID, 0, index);
                }

                PlayerCharacter entity = player.ToEntity();
                _db.PlayerCharacters.Add(entity);
                _db.SaveChanges();

                _db.StoredProcedure("InsertAllPCSkillsByID",
                                    new SqlParameter("PlayerID", player.GlobalID));

                _skill.ApplyStatChanges(player, null, true);

                _.DelayCommand(1.0f, () => _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectHeal(999), player.Object));

                InitializeHotBar(player);
            }
        }