Пример #1
0
        private static void InitializeDurability(NWItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            item.SetLocalInt("DURABILITY_OVERRIDE", TRUE);
            if (item.GetLocalInt("DURABILITY_INITIALIZE") <= 0 &&
                item.GetLocalFloat("DURABILITY_CURRENT") <= 0.0f)
            {
                float durability = GetMaxDurability(item) <= 0 ? DefaultDurability : GetMaxDurability(item);
                item.SetLocalFloat("DURABILITY_CURRENT", durability);
                if (item.GetLocalFloat("DURABILITY_MAX") <= 0.0f)
                {
                    float maxDurability = DefaultDurability;
                    foreach (var ip in item.ItemProperties)
                    {
                        if (_.GetItemPropertyType(ip) == (int)CustomItemPropertyType.MaxDurability)
                        {
                            maxDurability = _.GetItemPropertyCostTableValue(ip);
                            break;
                        }
                    }

                    item.SetLocalFloat("DURABILITY_MAX", maxDurability);
                }
            }
            item.SetLocalInt("DURABILITY_INITIALIZED", 1);
        }
Пример #2
0
        public void ApplyCraftedItemLocalVariables(NWItem item, BaseStructure structure)
        {
            // Structure items need an additional local variable and their name set on creation.
            if (structure != null)
            {
                item.SetLocalInt("BASE_STRUCTURE_ID", structure.ID);
                item.Name = structure.Name;

                if (structure.BaseStructureTypeID == (int)BaseStructureType.Building)
                {
                    var defaultInterior = _data.Single <BuildingStyle>(x => x.BaseStructureID == structure.ID && x.IsDefault && x.BuildingTypeID == (int)BuildingType.Interior && x.IsActive).ID;
                    var defaultExterior = _data.Single <BuildingStyle>(x => x.BaseStructureID == structure.ID && x.IsDefault && x.BuildingTypeID == (int)BuildingType.Exterior && x.IsActive).ID;

                    item.SetLocalInt("STRUCTURE_BUILDING_INTERIOR_ID", defaultInterior);
                    item.SetLocalInt("STRUCTURE_BUILDING_EXTERIOR_ID", defaultExterior);
                }
            }
        }
Пример #3
0
        public NWItem ConvertStructureToItem(PCBaseStructure pcBaseStructure, NWObject target)
        {
            var    baseStructure = _data.Get <BaseStructure>(pcBaseStructure.BaseStructureID);
            NWItem item          = (_.CreateItemOnObject(baseStructure.ItemResref, target.Object));

            item.SetLocalInt("BASE_STRUCTURE_ID", pcBaseStructure.BaseStructureID);
            item.Name = baseStructure.Name;

            _durability.SetMaxDurability(item, (float)pcBaseStructure.Durability);
            _durability.SetDurability(item, (float)pcBaseStructure.Durability);
            item.StructureBonus = pcBaseStructure.StructureBonus;

            if (pcBaseStructure.InteriorStyleID != null && pcBaseStructure.ExteriorStyleID != null)
            {
                item.SetLocalInt("STRUCTURE_BUILDING_INTERIOR_ID", (int)pcBaseStructure.InteriorStyleID);
                item.SetLocalInt("STRUCTURE_BUILDING_EXTERIOR_ID", (int)pcBaseStructure.ExteriorStyleID);
                item.SetLocalInt("STRUCTURE_BUILDING_INITIALIZED", TRUE);
            }

            return(item);
        }
Пример #4
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));
                }
            });
        }
Пример #5
0
        public bool Run(params object[] args)
        {
            NWPlaceable container = NWPlaceable.Wrap(Object.OBJECT_SELF);
            NWPlayer    oPC       = NWPlayer.Wrap(_.GetLastOpenedBy());
            var         items     = _db.PCOverflowItems.Where(x => x.PlayerID == oPC.GlobalID);

            foreach (PCOverflowItem item in items)
            {
                NWItem oItem = _serialization.DeserializeItem(item.ItemObject, container);
                oItem.SetLocalInt("TEMP_OVERFLOW_ITEM_ID", (int)item.PCOverflowItemID);
            }

            container.IsUseable = false;
            return(true);
        }
Пример #6
0
        public static void SetDurability(NWItem item, float value)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }
            if (value < 0.0f)
            {
                value = 0.0f;
            }

            item.SetLocalInt("DURABILITY_OVERRIDE", TRUE);
            InitializeDurability(item);
            item.SetLocalFloat("DURABILITY_CURRENT", value);
        }
Пример #7
0
        public static void SetMaxDurability(NWItem item, float value)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            item.SetLocalInt("DURABILITY_OVERRIDE", TRUE);
            if (value <= 0)
            {
                value = DefaultDurability;
            }

            item.SetLocalFloat("DURABILITY_MAX", value);
            InitializeDurability(item);
        }
Пример #8
0
        public static void AddCardToDeck(int collectionIndex, NWItem collection, int deckIndex)
        {
            // Adds the card at position card in collection to slot in the collection's active deck.
            // First check that the card is not in the deck.
            for (int ii = 1; ii <= 10; ii++)
            {
                int cardInDeck = collection.GetLocalInt("DECK_" + ii);
                if (cardInDeck == collectionIndex)
                {
                    _.SendMessageToPC(_.GetItemPossessor(collection), "You cannot add a card that's already in your play deck.");
                    return;
                }
            }

            collection.SetLocalInt("DECK_" + deckIndex, collectionIndex);
        }
Пример #9
0
        private void InitializeDurability(NWItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            if (!IsValidDurabilityType(item))
            {
                return;
            }

            if (item.GetLocalInt("DURABILITY_INITIALIZE") <= 0 &&
                item.GetLocalFloat("DURABILITY_CURRENT") <= 0.0f)
            {
                float durability = GetMaxDurability(item) <= 0 ? DefaultDurability : GetMaxDurability(item);
                item.SetLocalFloat("DURABILITY_CURRENT", durability);
            }
            item.SetLocalInt("DURABILITY_INITIALIZED", 1);
        }
Пример #10
0
        public static void RemoveCardFromCollection(int index, NWItem collection)
        {
            // removes the card at index card, creating a card object with the right variable in the player's inventory.
            // First check that the card is not in the deck.
            for (int ii = 1; ii <= 10; ii++)
            {
                int cardInDeck = collection.GetLocalInt("DECK_" + ii);
                if (cardInDeck == index)
                {
                    _.SendMessageToPC(_.GetItemPossessor(collection), "You cannot remove a card that's in your play deck.");
                    return;
                }
            }

            // All good - extract it.
            NWItem card = _.CreateItemOnObject("pazaakcard", _.GetItemPossessor(collection));

            card.SetLocalInt("PAZAAK_CARD_TYPE", collection.GetLocalInt("CARD_" + index));
            card.Name = "Pazaak Card (" + Display(collection.GetLocalInt("CARD_" + index)) + ")";
            collection.DeleteLocalInt("CARD_" + index);
            return;
        }
Пример #11
0
        public void Main()
        {
            NWPlaceable terminal = NWGameObject.OBJECT_SELF;
            int         bankID   = terminal.GetLocalInt("BANK_ID");

            if (bankID <= 0)
            {
                return;
            }

            NWPlayer player      = _.GetLastDisturbed();
            NWItem   item        = _.GetInventoryDisturbItem();
            int      disturbType = _.GetInventoryDisturbType();
            int      itemCount   = terminal.InventoryItems.Count();
            int      itemLimit   = terminal.GetLocalInt("BANK_LIMIT");

            if (itemLimit <= 0)
            {
                itemLimit = 20;
            }

            if (disturbType == _.INVENTORY_DISTURB_TYPE_ADDED)
            {
                if (_.GetHasInventory(item) == _.TRUE)
                {
                    item.SetLocalInt("RETURNING_ITEM", _.TRUE);
                    ItemService.ReturnItem(player, item);
                    player.SendMessage(ColorTokenService.Red("Containers cannot currently be stored inside banks."));
                    return;
                }

                if (itemCount > itemLimit)
                {
                    ItemService.ReturnItem(player, item);
                    player.SendMessage(ColorTokenService.Red("No more items can be placed inside."));
                }
                else
                {
                    BankItem itemEntity = new BankItem
                    {
                        ItemName   = item.Name,
                        ItemTag    = item.Tag,
                        ItemResref = item.Resref,
                        ItemID     = item.GlobalID.ToString(),
                        ItemObject = SerializationService.Serialize(item),
                        BankID     = bankID,
                        PlayerID   = player.GlobalID,
                        DateStored = DateTime.UtcNow
                    };

                    DataService.SubmitDataChange(itemEntity, DatabaseActionType.Insert);
                    MessageHub.Instance.Publish(new OnStoreBankItem(player, itemEntity));
                }
            }
            else if (disturbType == _.INVENTORY_DISTURB_TYPE_REMOVED)
            {
                if (item.GetLocalInt("RETURNING_ITEM") == _.TRUE)
                {
                    item.DeleteLocalInt("RETURNING_ITEM");
                }
                else
                {
                    var record = DataService.BankItem.GetByItemID(item.GlobalID.ToString());
                    DataService.SubmitDataChange(record, DatabaseActionType.Delete);
                    MessageHub.Instance.Publish(new OnRemoveBankItem(player, record));
                }
            }

            player.SendMessage(ColorTokenService.White("Item Limit: " + (itemCount > itemLimit ? itemLimit : itemCount) + " / ") + ColorTokenService.Red("" + itemLimit));
        }
Пример #12
0
        public void ApplyEffects(NWCreature user, NWItem modItem, NWObject target, Location targetLocation, CustomData customData)
        {
            NWPlayer player                = (user.Object);
            NWItem   targetItem            = (target.Object);
            ModSlots slots                 = _mod.GetModSlots(targetItem);
            CustomItemPropertyType modType = _mod.GetModType(modItem);
            int modID = modItem.GetLocalInt("RUNE_ID");

            string[] modArgs       = modItem.GetLocalString("RUNE_VALUE").Split(',');
            int      modLevel      = modItem.RecommendedLevel;
            int      levelIncrease = modItem.LevelIncrease;

            var dbMod = _data.Single <Data.Entity.Mod>(x => x.ID == modID && x.IsActive);

            App.ResolveByInterface <IMod>("Mod." + dbMod.Script, mod =>
            {
                mod.Apply(player, targetItem, modArgs);

                string description = mod.Description(player, targetItem, modArgs);
                bool usePrismatic  = false;
                switch (modType)
                {
                case CustomItemPropertyType.RedMod:
                    if (slots.FilledRedSlots < slots.RedSlots)
                    {
                        targetItem.SetLocalInt("MOD_SLOT_RED_" + (slots.FilledRedSlots + 1), modID);
                        targetItem.SetLocalString("MOD_SLOT_RED_DESC_" + (slots.FilledRedSlots + 1), description);
                        player.SendMessage("Mod installed into " + _color.Red("red") + " slot #" + (slots.FilledRedSlots + 1));
                    }
                    else
                    {
                        usePrismatic = true;
                    }
                    break;

                case CustomItemPropertyType.BlueMod:
                    if (slots.FilledBlueSlots < slots.BlueSlots)
                    {
                        targetItem.SetLocalInt("MOD_SLOT_BLUE_" + (slots.FilledBlueSlots + 1), modID);
                        targetItem.SetLocalString("MOD_SLOT_BLUE_DESC_" + (slots.FilledBlueSlots + 1), description);
                        player.SendMessage("Mod installed into " + _color.Blue("blue") + " slot #" + (slots.FilledBlueSlots + 1));
                    }
                    else
                    {
                        usePrismatic = true;
                    }
                    break;

                case CustomItemPropertyType.GreenMod:
                    if (slots.FilledBlueSlots < slots.GreenSlots)
                    {
                        targetItem.SetLocalInt("MOD_SLOT_GREEN_" + (slots.FilledGreenSlots + 1), modID);
                        targetItem.SetLocalString("MOD_SLOT_GREEN_DESC_" + (slots.FilledGreenSlots + 1), description);
                        player.SendMessage("Mod installed into " + _color.Green("green") + " slot #" + (slots.FilledGreenSlots + 1));
                    }
                    else
                    {
                        usePrismatic = true;
                    }
                    break;

                case CustomItemPropertyType.YellowMod:
                    if (slots.FilledBlueSlots < slots.YellowSlots)
                    {
                        targetItem.SetLocalInt("MOD_SLOT_YELLOW_" + (slots.FilledYellowSlots + 1), modID);
                        targetItem.SetLocalString("MOD_SLOT_YELLOW_DESC_" + (slots.FilledYellowSlots + 1), description);
                        player.SendMessage("Mod installed into " + _color.Yellow("yellow") + " slot #" + (slots.FilledYellowSlots + 1));
                    }
                    else
                    {
                        usePrismatic = true;
                    }
                    break;
                }

                if (usePrismatic)
                {
                    string prismaticText = _mod.PrismaticString();
                    targetItem.SetLocalInt("MOD_SLOT_PRISMATIC_" + (slots.FilledPrismaticSlots + 1), modID);
                    targetItem.SetLocalString("MOD_SLOT_PRISMATIC_DESC_" + (slots.FilledPrismaticSlots + 1), description);
                    player.SendMessage("Mod installed into " + prismaticText + " slot #" + (slots.FilledPrismaticSlots + 1));
                }

                targetItem.RecommendedLevel += levelIncrease;
                modItem.Destroy();

                SkillType skillType;
                if (ItemService.ArmorBaseItemTypes.Contains(targetItem.BaseItemType))
                {
                    skillType = SkillType.Armorsmith;
                }
                else if (ItemService.WeaponBaseItemTypes.Contains(targetItem.BaseItemType))
                {
                    skillType = SkillType.Weaponsmith;
                }
                else
                {
                    return;
                }

                int rank = _skill.GetPCSkillRank(player, skillType);
                int xp   = (int)_skill.CalculateRegisteredSkillLevelAdjustedXP(400, modLevel, rank);
                _skill.GiveSkillXP(player, skillType, xp);
            });
        }
Пример #13
0
        public void DoPerkUpgrade(NWPlayer oPC, int perkID, bool freeUpgrade = false)
        {
            var perk       = _data.Single <Data.Entity.Perk>(x => x.ID == perkID);
            var perkLevels = _data.Where <PerkLevel>(x => x.PerkID == perkID);
            var pcPerk     = _data.SingleOrDefault <PCPerk>(x => x.PlayerID == oPC.GlobalID && x.PerkID == perkID);
            var player     = _data.Single <Player>(x => x.ID == oPC.GlobalID);

            if (freeUpgrade || CanPerkBeUpgraded(oPC, perkID))
            {
                DatabaseActionType action = DatabaseActionType.Update;
                if (pcPerk == null)
                {
                    pcPerk = new PCPerk();
                    DateTime dt = DateTime.UtcNow;
                    pcPerk.AcquiredDate = dt;
                    pcPerk.PerkID       = perk.ID;
                    pcPerk.PlayerID     = oPC.GlobalID;
                    pcPerk.PerkLevel    = 0;

                    action = DatabaseActionType.Insert;
                }

                PerkLevel nextPerkLevel = FindPerkLevel(perkLevels, pcPerk.PerkLevel + 1);
                if (nextPerkLevel == null)
                {
                    return;
                }

                pcPerk.PerkLevel++;
                _data.SubmitDataChange(pcPerk, action);

                if (!freeUpgrade)
                {
                    player.UnallocatedSP -= nextPerkLevel.Price;
                    _data.SubmitDataChange(player, DatabaseActionType.Update);
                }

                // If a perk is activatable, create the item on the PC.
                // Remove any existing cast spell unique power properties and add the correct one based on the DB flag.
                if (!string.IsNullOrWhiteSpace(perk.ItemResref))
                {
                    if (_.GetIsObjectValid(_.GetItemPossessedBy(oPC.Object, perk.ItemResref)) == FALSE)
                    {
                        NWItem spellItem = (_.CreateItemOnObject(perk.ItemResref, oPC.Object));
                        spellItem.IsCursed = true;
                        spellItem.SetLocalInt("ACTIVATION_PERK_ID", perk.ID);

                        foreach (ItemProperty ipCur in spellItem.ItemProperties)
                        {
                            int ipType    = _.GetItemPropertyType(ipCur);
                            int ipSubType = _.GetItemPropertySubType(ipCur);
                            if (ipType == ITEM_PROPERTY_CAST_SPELL &&
                                (ipSubType == IP_CONST_CASTSPELL_UNIQUE_POWER ||
                                 ipSubType == IP_CONST_CASTSPELL_UNIQUE_POWER_SELF_ONLY ||
                                 ipSubType == IP_CONST_CASTSPELL_ACTIVATE_ITEM))
                            {
                                _.RemoveItemProperty(spellItem.Object, ipCur);
                            }
                        }

                        ItemProperty ip;
                        if (perk.IsTargetSelfOnly)
                        {
                            ip = _.ItemPropertyCastSpell(IP_CONST_CASTSPELL_UNIQUE_POWER_SELF_ONLY, IP_CONST_CASTSPELL_NUMUSES_UNLIMITED_USE);
                        }
                        else
                        {
                            ip = _.ItemPropertyCastSpell(IP_CONST_CASTSPELL_UNIQUE_POWER, IP_CONST_CASTSPELL_NUMUSES_UNLIMITED_USE);
                        }

                        _biowareXP2.IPSafeAddItemProperty(spellItem, ip, 0.0f, AddItemPropertyPolicy.ReplaceExisting, false, false);
                    }

                    _.SetName(_.GetItemPossessedBy(oPC.Object, perk.ItemResref), perk.Name + " (Lvl. " + pcPerk.PerkLevel + ")");
                }
                // If a feat ID is assigned, add the feat to the player if it doesn't exist yet.
                else if (perk.FeatID != null &&
                         perk.FeatID > 0 &&
                         _.GetHasFeat((int)perk.FeatID, oPC.Object) == FALSE)
                {
                    _nwnxCreature.AddFeatByLevel(oPC, (int)perk.FeatID, 1);

                    var qbs = _nwnxQBS.UseFeat((int)perk.FeatID);

                    // Try to add the new feat to the player's hotbar.
                    if (_nwnxPlayer.GetQuickBarSlot(oPC, 0).ObjectType == QuickBarSlotType.Empty)
                    {
                        _nwnxPlayer.SetQuickBarSlot(oPC, 0, qbs);
                    }
                    else if (_nwnxPlayer.GetQuickBarSlot(oPC, 1).ObjectType == QuickBarSlotType.Empty)
                    {
                        _nwnxPlayer.SetQuickBarSlot(oPC, 1, qbs);
                    }
                    else if (_nwnxPlayer.GetQuickBarSlot(oPC, 2).ObjectType == QuickBarSlotType.Empty)
                    {
                        _nwnxPlayer.SetQuickBarSlot(oPC, 2, qbs);
                    }
                    else if (_nwnxPlayer.GetQuickBarSlot(oPC, 3).ObjectType == QuickBarSlotType.Empty)
                    {
                        _nwnxPlayer.SetQuickBarSlot(oPC, 3, qbs);
                    }
                    else if (_nwnxPlayer.GetQuickBarSlot(oPC, 4).ObjectType == QuickBarSlotType.Empty)
                    {
                        _nwnxPlayer.SetQuickBarSlot(oPC, 4, qbs);
                    }
                    else if (_nwnxPlayer.GetQuickBarSlot(oPC, 5).ObjectType == QuickBarSlotType.Empty)
                    {
                        _nwnxPlayer.SetQuickBarSlot(oPC, 5, qbs);
                    }
                    else if (_nwnxPlayer.GetQuickBarSlot(oPC, 6).ObjectType == QuickBarSlotType.Empty)
                    {
                        _nwnxPlayer.SetQuickBarSlot(oPC, 6, qbs);
                    }
                    else if (_nwnxPlayer.GetQuickBarSlot(oPC, 7).ObjectType == QuickBarSlotType.Empty)
                    {
                        _nwnxPlayer.SetQuickBarSlot(oPC, 7, qbs);
                    }
                    else if (_nwnxPlayer.GetQuickBarSlot(oPC, 8).ObjectType == QuickBarSlotType.Empty)
                    {
                        _nwnxPlayer.SetQuickBarSlot(oPC, 8, qbs);
                    }
                    else if (_nwnxPlayer.GetQuickBarSlot(oPC, 9).ObjectType == QuickBarSlotType.Empty)
                    {
                        _nwnxPlayer.SetQuickBarSlot(oPC, 9, qbs);
                    }
                    else if (_nwnxPlayer.GetQuickBarSlot(oPC, 10).ObjectType == QuickBarSlotType.Empty)
                    {
                        _nwnxPlayer.SetQuickBarSlot(oPC, 10, qbs);
                    }
                }

                oPC.SendMessage(_color.Green("Perk Purchased: " + perk.Name + " (Lvl. " + pcPerk.PerkLevel + ")"));

                App.ResolveByInterface <IPerk>("Perk." + perk.ScriptName, (perkScript) =>
                {
                    if (perkScript == null)
                    {
                        return;
                    }
                    perkScript.OnPurchased(oPC, pcPerk.PerkLevel);
                });
            }
            else
            {
                oPC.FloatingText(_color.Red("You cannot purchase the perk at this time."));
            }
        }
Пример #14
0
        public override void DoAction(NWPlayer player, string pageName, int responseID)
        {
            PlayerDialog    dialog      = DialogService.LoadPlayerDialog(GetPC().GlobalID);
            Guid            structureID = new Guid(_.GetLocalString(player.Area, "PC_BASE_STRUCTURE_ID"));
            PCBaseStructure structure   = DataService.PCBaseStructure.GetByID(structureID);
            PCBase          pcBase      = DataService.PCBase.GetByID(structure.PCBaseID);

            DialogPage     page     = dialog.GetPageByName(pageName);
            DialogResponse response = page.Responses[responseID - 1];

            bool carefulPilot = PerkService.GetCreaturePerkLevel(player, PerkType.CarefulPilot) > 0;

            if (pageName == "MainPage")
            {
                // The number of dialog options available can vary.  So query based on the actual text of the response.
                if (response.Text == "Land")
                {
                    ChangePage("LandingDestPage");
                }
                else if (response.Text == "Pilot Ship")
                {
                    SpaceService.CreateShipInSpace(player.Area); // In case we logged in here.
                    SpaceService.DoFlyShip(GetPC(), GetPC().Area);
                    EndConversation();
                }
                else if (response.Text == "Hyperspace Jump")
                {
                    // Build the list of destinations.
                    ChangePage("HyperDestPage");
                }
                else if (response.Text == "Take Off")
                {
                    // Check fuel
                    if (pcBase.Fuel < 1)
                    {
                        GetPC().SendMessage("You don't have enough fuel! You need 1 fuel to take off.");
                        dialog.ResetPage();
                    }
                    else
                    {
                        // Fuel is good - we have liftoff.
                        if (!SpaceService.DoPilotingSkillCheck(GetPC(), 2, carefulPilot))
                        {
                            // Failed our skill check.  Deduct fuel but don't do anything else.
                            GetPC().FloatingText("The ship shudders a bit, but your awkwardness on the throttle shows, and it doesn't make it off the dock.  Try again.");
                            pcBase.Fuel -= 1;
                            DataService.SubmitDataChange(pcBase, DatabaseActionType.Update);
                            return;
                        }

                        EndConversation();

                        // Save details of the current dock for later.
                        Guid            shipPCBaseID = new Guid(pcBase.ShipLocation);
                        PCBaseStructure dock         = DataService.PCBaseStructure.GetByIDOrDefault(shipPCBaseID);

                        pcBase.Fuel        -= 1;
                        pcBase.DateRentDue  = DateTime.UtcNow.AddDays(99);
                        pcBase.ShipLocation = SpaceService.GetPlanetFromLocation(pcBase.ShipLocation) + " - Orbit";
                        DataService.SubmitDataChange(pcBase, DatabaseActionType.Update);

                        SpaceService.CreateShipInSpace(player.Area);

                        // Give the impression of movement
                        foreach (var creature in player.Area.Objects)
                        {
                            if (creature.IsPC || creature.IsDM)
                            {
                                _.FloatingTextStringOnCreature("The ship is taking off", creature);
                            }
                        }

                        _.ApplyEffectToObject(DurationType.Instant, _.EffectVisualEffect(VisualEffect.Vfx_Fnf_Screen_Shake), player);

                        // Clean up the base structure, if we were in a PC dock not public starport.
                        // Get a reference to our placeable (and door), and delete them with some VFX.
                        if (dock != null)
                        {
                            PCBase dockBase = DataService.PCBase.GetByID(dock.PCBaseID);

                            IEnumerable <NWArea> areas = NWModule.Get().Areas;
                            NWArea landingArea         = new NWArea(_.GetFirstArea());

                            foreach (var area in areas)
                            {
                                if (_.GetResRef(area) == dockBase.AreaResref)
                                {
                                    landingArea = area;
                                }
                            }

                            List <AreaStructure> areaStructures = landingArea.Data["BASE_SERVICE_STRUCTURES"];
                            foreach (var plc in areaStructures)
                            {
                                if (plc.PCBaseStructureID == dock.ID)
                                {
                                    // Found our dock.  Clear its variable and play some VFX.
                                    plc.Structure.SetLocalInt("DOCKED_STARSHIP", 0);
                                    DoDustClouds(plc.Structure.Location);
                                    _.ApplyEffectToObject(DurationType.Instant, _.EffectVisualEffect(VisualEffect.Vfx_Fnf_Screen_Shake), plc.Structure);
                                }
                                else if (plc.PCBaseStructureID == structure.ID)
                                {
                                    // found either our ship or our entrance (both are saved with our structure ID).  Delete them.
                                    // Dp NOT remove the PC base structure object from the database.  We still need that.
                                    plc.Structure.Destroy();
                                }
                            }
                        }
                    }
                }
                else if (response.Text == "Access Fuel Bay")
                {
                    OpenFuelBay(false);
                    EndConversation();
                }
                else if (response.Text == "Access Stronidium Bay")
                {
                    OpenFuelBay(true);
                    EndConversation();
                }
                else if (response.Text == "Access Resource Bay")
                {
                    NWPlaceable bay = SpaceService.GetCargoBay(player.Area, GetPC());
                    if (bay != null)
                    {
                        GetPC().AssignCommand(() => _.ActionInteractObject(bay.Object));
                    }
                    EndConversation();
                }
                else if (response.Text == "Export Starcharts")
                {
                    NWItem item = _.CreateItemOnObject("starcharts", player, 1, _.Random(10000).ToString());

                    // Initialise the list, in case it hasn't been populated yet.
                    SpaceService.GetHyperspaceDestinationList(pcBase);

                    item.SetLocalInt("Starcharts", (int)pcBase.Starcharts);
                }
            }
            else if (pageName == "HyperDestPage")
            {
                // Check fuel
                if (pcBase.Fuel < 50)
                {
                    GetPC().SendMessage("You don't have enough fuel! You need 50 fuel to make a hyperspace jump.");
                    dialog.ResetPage();
                }
                else
                {
                    // Fuel is good - make the jump
                    if (!SpaceService.DoPilotingSkillCheck(GetPC(), 13, carefulPilot))
                    {
                        // Failed our skill check.  Deduct fuel but don't do anything else.
                        GetPC().FloatingText("Jump failed!  You forgot to whatsit the thingummyjig.");
                        pcBase.Fuel -= 50;
                        DataService.SubmitDataChange(pcBase, DatabaseActionType.Update);
                        EndConversation();
                        return;
                    }

                    // Move the ship out of the old orbit.
                    SpaceService.RemoveShipInSpace(player.Area);

                    // Fade to black for hyperspace.
                    EndConversation();
                    pcBase.Fuel        -= 50;
                    pcBase.ShipLocation = response.Text + " - Orbit";
                    DataService.SubmitDataChange(pcBase, DatabaseActionType.Update);

                    // Put the ship in its new orbit.
                    SpaceService.CreateShipInSpace(player.Area);

                    // Give the impression of movement - would be great to have the actual hyperspace jump graphics here.
                    foreach (var creature in player.Area.Objects)
                    {
                        if (creature.IsPC || creature.IsDM)
                        {
                            _.FloatingTextStringOnCreature("Making a hyperspace jump!", creature);
                            _.FadeToBlack(creature, 0.5f);
                            _.DelayCommand(1.0f, () => { _.FadeFromBlack(creature, 0.5f); });
                        }
                    }
                }
            }
            else if (pageName == "LandingDestPage")
            {
                // Skill check.
                if (!SpaceService.DoPilotingSkillCheck(GetPC(), 5, carefulPilot))
                {
                    // Failed our skill check.  Land anyway but burn more fuel.
                    if (pcBase.Fuel > 0)
                    {
                        GetPC().FloatingText("You overshoot the landing spot, burning extra fuel getting your ship into position.");
                        pcBase.Fuel -= 1;
                        DataService.SubmitDataChange(pcBase, DatabaseActionType.Update);
                    }
                }

                // Get the response, then find the structure ID.
                Guid dockStructureID = dialog.CustomData["LAND_" + response.Text];

                // This could be a public startport ID or a private dock base structure ID.
                Starport starport = DataService.Starport.GetByStarportIDOrDefault(dockStructureID);
                if (starport != null)
                {
                    // We have a public starport.
                    if (player.Gold < starport.Cost)
                    {
                        player.SendMessage("You do not have enough credits to land here.");
                        return;
                    }
                    else
                    {
                        _.TakeGoldFromCreature(starport.Cost, player, true);

                        // Land.
                        pcBase.ShipLocation = starport.StarportID.ToString();
                        pcBase.DateRentDue  = DateTime.UtcNow.AddDays(1);
                        DataService.SubmitDataChange(pcBase, DatabaseActionType.Update);

                        // Notify PC.
                        player.SendMessage("You have paid your first day's berthing fees. Use the Base Management System to extend your lease if you plan to stay longer, or your ship will be impounded.");

                        EndConversation();
                    }
                }
                else
                {
                    LoggingService.Trace(TraceComponent.Space, "Landing in PC base dock, ID: " + dockStructureID.ToString());
                    PCBaseStructure dock = DataService.PCBaseStructure.GetByIDOrDefault(dockStructureID);

                    if (dock == null)
                    {
                        player.SendMessage("ERROR: Could not find landing dock by ID.  Please report this.");
                        LoggingService.Trace(TraceComponent.Space, "Could not find landing dock ID " + dockStructureID.ToString());
                        return;
                    }

                    NWPlaceable plc = BaseService.FindPlaceableFromStructureID(dock.ID.ToString());

                    if (plc == null)
                    {
                        LoggingService.Trace(TraceComponent.Space, "Failed to find dock placeable.");
                        player.SendMessage("ERROR: Could not find landing dock placeable.  Please report this.");
                        return;
                    }

                    LoggingService.Trace(TraceComponent.Space, "Found dock, landing ship.");

                    // We've found our dock. Update our record of where the ship's exterior should spawn.
                    NWLocation loc = plc.Location;

                    structure.LocationX           = loc.X;
                    structure.LocationY           = loc.Y;
                    structure.LocationZ           = loc.Z;
                    structure.LocationOrientation = _.GetFacingFromLocation(loc);

                    DataService.SubmitDataChange(structure, DatabaseActionType.Update);

                    // And update the base to mark the parent dock as the location.
                    pcBase.ShipLocation = dock.ID.ToString();
                    DataService.SubmitDataChange(pcBase, DatabaseActionType.Update);

                    // Now use the Base Service to spawn the ship exterior.
                    BaseService.SpawnStructure(plc.Area, structure.ID);

                    // Mark the dock as occupied.
                    plc.SetLocalInt("DOCKED_STARSHIP", 1);

                    // Notify PCs in the landing area.
                    foreach (var creature in plc.Area.Objects)
                    {
                        if (creature.IsPC || creature.IsDM)
                        {
                            _.FloatingTextStringOnCreature("A ship has just landed!", creature);
                        }
                    }

                    // And shake the screen, because stuff.
                    _.ApplyEffectAtLocation(DurationType.Instant, _.EffectVisualEffect(VisualEffect.Vfx_Fnf_Screen_Shake), loc);
                    DoDustClouds(loc);
                }

                // We're landing.  Make sure any pilot or gunner get out of flight mode.
                SpaceService.LandCrew(player.Area);

                // If we are still here, we landed successfully.  Shake the screen about and notify PCs on the ship.
                // Give the impression of movement
                foreach (var creature in player.Area.Objects)
                {
                    if (creature.IsPC || creature.IsDM)
                    {
                        _.FloatingTextStringOnCreature("The ship is landing.", creature);
                    }
                }

                _.ApplyEffectToObject(DurationType.Instant, _.EffectVisualEffect(VisualEffect.Vfx_Fnf_Screen_Shake), player);
                SpaceService.RemoveShipInSpace(player.Area);

                EndConversation();
            }
        }
Пример #15
0
        public void ApplyEffects(NWCreature user, NWItem modItem, NWObject target, Location targetLocation, CustomData customData)
        {
            NWPlayer         player     = (user.Object);
            NWItem           targetItem = (target.Object);
            ModSlots         slots      = ModService.GetModSlots(targetItem);
            ItemPropertyType modType    = ModService.GetModType(modItem);
            int modID = modItem.GetLocalInt("RUNE_ID");

            string[] modArgs       = modItem.GetLocalString("RUNE_VALUE").Split(',');
            int      modLevel      = modItem.RecommendedLevel;
            int      levelIncrease = modItem.LevelIncrease;

            var mod = ModService.GetModHandler(modID);

            mod.Apply(player, targetItem, modArgs);

            string description  = mod.Description(player, targetItem, modArgs);
            bool   usePrismatic = false;

            switch (modType)
            {
            case ItemPropertyType.RedMod:
                if (slots.FilledRedSlots < slots.RedSlots)
                {
                    targetItem.SetLocalInt("MOD_SLOT_RED_" + (slots.FilledRedSlots + 1), modID);
                    targetItem.SetLocalString("MOD_SLOT_RED_DESC_" + (slots.FilledRedSlots + 1), description);
                    player.SendMessage("Mod installed into " + ColorTokenService.Red("red") + " slot #" + (slots.FilledRedSlots + 1));
                }
                else
                {
                    usePrismatic = true;
                }
                break;

            case ItemPropertyType.BlueMod:
                if (slots.FilledBlueSlots < slots.BlueSlots)
                {
                    targetItem.SetLocalInt("MOD_SLOT_BLUE_" + (slots.FilledBlueSlots + 1), modID);
                    targetItem.SetLocalString("MOD_SLOT_BLUE_DESC_" + (slots.FilledBlueSlots + 1), description);
                    player.SendMessage("Mod installed into " + ColorTokenService.Blue("blue") + " slot #" + (slots.FilledBlueSlots + 1));
                }
                else
                {
                    usePrismatic = true;
                }
                break;

            case ItemPropertyType.GreenMod:
                if (slots.FilledGreenSlots < slots.GreenSlots)
                {
                    targetItem.SetLocalInt("MOD_SLOT_GREEN_" + (slots.FilledGreenSlots + 1), modID);
                    targetItem.SetLocalString("MOD_SLOT_GREEN_DESC_" + (slots.FilledGreenSlots + 1), description);
                    player.SendMessage("Mod installed into " + ColorTokenService.Green("green") + " slot #" + (slots.FilledGreenSlots + 1));
                }
                else
                {
                    usePrismatic = true;
                }
                break;

            case ItemPropertyType.YellowMod:
                if (slots.FilledYellowSlots < slots.YellowSlots)
                {
                    targetItem.SetLocalInt("MOD_SLOT_YELLOW_" + (slots.FilledYellowSlots + 1), modID);
                    targetItem.SetLocalString("MOD_SLOT_YELLOW_DESC_" + (slots.FilledYellowSlots + 1), description);
                    player.SendMessage("Mod installed into " + ColorTokenService.Yellow("yellow") + " slot #" + (slots.FilledYellowSlots + 1));
                }
                else
                {
                    usePrismatic = true;
                }
                break;
            }

            if (usePrismatic)
            {
                string prismaticText = ModService.PrismaticString();
                targetItem.SetLocalInt("MOD_SLOT_PRISMATIC_" + (slots.FilledPrismaticSlots + 1), modID);
                targetItem.SetLocalString("MOD_SLOT_PRISMATIC_DESC_" + (slots.FilledPrismaticSlots + 1), description);
                player.SendMessage("Mod installed into " + prismaticText + " slot #" + (slots.FilledPrismaticSlots + 1));
            }

            targetItem.RecommendedLevel += levelIncrease;
            modItem.Destroy();

            SkillType skillType;

            if (GetLocalBool(targetItem, "LIGHTSABER") == true)
            {
                skillType = SkillType.Engineering;
            }
            else if (ArmorBaseItemTypes.Contains(targetItem.BaseItemType))
            {
                skillType = SkillType.Armorsmith;
            }
            else if (WeaponsmithBaseItemTypes.Contains(targetItem.BaseItemType))
            {
                skillType = SkillType.Weaponsmith;
            }
            else if (EngineeringBaseItemTypes.Contains(targetItem.BaseItemType))
            {
                skillType = SkillType.Engineering;
            }
            else
            {
                return;
            }

            int rank = SkillService.GetPCSkillRank(player, skillType);
            int xp   = (int)SkillService.CalculateRegisteredSkillLevelAdjustedXP(400, modLevel, rank);

            SkillService.GiveSkillXP(player, skillType, xp);
        }
Пример #16
0
        public bool Run(params object[] args)
        {
            NWPlaceable terminal = Object.OBJECT_SELF;
            int         bankID   = terminal.GetLocalInt("BANK_ID");

            if (bankID <= 0)
            {
                return(false);
            }

            NWPlayer player      = _.GetLastDisturbed();
            NWItem   item        = _.GetInventoryDisturbItem();
            int      disturbType = _.GetInventoryDisturbType();
            int      itemCount   = terminal.InventoryItems.Count();
            int      itemLimit   = terminal.GetLocalInt("BANK_LIMIT");

            if (itemLimit <= 0)
            {
                itemLimit = 20;
            }

            if (disturbType == INVENTORY_DISTURB_TYPE_ADDED)
            {
                if (_.GetHasInventory(item) == TRUE)
                {
                    item.SetLocalInt("RETURNING_ITEM", TRUE);
                    _item.ReturnItem(player, item);
                    player.SendMessage(_color.Red("Containers cannot currently be stored inside banks."));
                    return(false);
                }

                if (itemCount > itemLimit)
                {
                    _item.ReturnItem(player, item);
                    player.SendMessage(_color.Red("No more items can be placed inside."));
                }
                else
                {
                    BankItem itemEntity = new BankItem
                    {
                        ItemName   = item.Name,
                        ItemTag    = item.Tag,
                        ItemResref = item.Resref,
                        ItemID     = item.GlobalID.ToString(),
                        ItemObject = _serialization.Serialize(item),
                        BankID     = bankID,
                        PlayerID   = player.GlobalID,
                        DateStored = DateTime.UtcNow
                    };

                    _data.SubmitDataChange(itemEntity, DatabaseActionType.Insert);
                }
            }
            else if (disturbType == INVENTORY_DISTURB_TYPE_REMOVED)
            {
                if (item.GetLocalInt("RETURNING_ITEM") == TRUE)
                {
                    item.DeleteLocalInt("RETURNING_ITEM");
                }
                else
                {
                    var record = _data.Single <BankItem>(x => x.ItemID == item.GlobalID.ToString());
                    _data.SubmitDataChange(record, DatabaseActionType.Delete);
                }
            }

            player.SendMessage(_color.White("Item Limit: " + (itemCount > itemLimit ? itemLimit : itemCount) + " / ") + _color.Red("" + itemLimit));
            return(true);
        }
Пример #17
0
        public void ApplyEffects(NWCreature user, NWItem runeItem, NWObject target, Location targetLocation, CustomData customData)
        {
            NWPlayer  player                = NWPlayer.Wrap(user.Object);
            NWItem    targetItem            = NWItem.Wrap(target.Object);
            RuneSlots slots                 = _rune.GetRuneSlots(targetItem);
            CustomItemPropertyType runeType = _rune.GetRuneType(runeItem);
            int runeID = runeItem.GetLocalInt("RUNE_ID");

            string[] runeArgs      = runeItem.GetLocalString("RUNE_VALUE").Split(',');
            int      runeLevel     = runeItem.RecommendedLevel;
            int      levelIncrease = runeItem.LevelIncrease;

            var   dbRune = _db.Runes.Single(x => x.RuneID == runeID && x.IsActive);
            IRune rune   = App.ResolveByInterface <IRune>("Rune." + dbRune.Script);

            rune.Apply(player, targetItem, runeArgs);

            string description  = rune.Description(player, targetItem, runeArgs);
            bool   usePrismatic = false;

            switch (runeType)
            {
            case CustomItemPropertyType.RedRune:
                if (slots.FilledRedSlots < slots.RedSlots)
                {
                    targetItem.SetLocalInt("RUNIC_SLOT_RED_" + (slots.FilledRedSlots + 1), runeID);
                    targetItem.SetLocalString("RUNIC_SLOT_RED_DESC_" + (slots.FilledRedSlots + 1), description);
                    player.SendMessage("Rune installed into " + _color.Red("red") + " slot #" + (slots.FilledRedSlots + 1));
                }
                else
                {
                    usePrismatic = true;
                }
                break;

            case CustomItemPropertyType.BlueRune:
                if (slots.FilledBlueSlots < slots.BlueSlots)
                {
                    targetItem.SetLocalInt("RUNIC_SLOT_BLUE_" + (slots.FilledBlueSlots + 1), runeID);
                    targetItem.SetLocalString("RUNIC_SLOT_BLUE_DESC_" + (slots.FilledBlueSlots + 1), description);
                    player.SendMessage("Rune installed into " + _color.Blue("blue") + " slot #" + (slots.FilledBlueSlots + 1));
                }
                else
                {
                    usePrismatic = true;
                }
                break;

            case CustomItemPropertyType.GreenRune:
                if (slots.FilledBlueSlots < slots.GreenSlots)
                {
                    targetItem.SetLocalInt("RUNIC_SLOT_GREEN_" + (slots.FilledGreenSlots + 1), runeID);
                    targetItem.SetLocalString("RUNIC_SLOT_GREEN_DESC_" + (slots.FilledGreenSlots + 1), description);
                    player.SendMessage("Rune installed into " + _color.Green("green") + " slot #" + (slots.FilledGreenSlots + 1));
                }
                else
                {
                    usePrismatic = true;
                }
                break;

            case CustomItemPropertyType.YellowRune:
                if (slots.FilledBlueSlots < slots.YellowSlots)
                {
                    targetItem.SetLocalInt("RUNIC_SLOT_YELLOW_" + (slots.FilledYellowSlots + 1), runeID);
                    targetItem.SetLocalString("RUNIC_SLOT_YELLOW_DESC_" + (slots.FilledYellowSlots + 1), description);
                    player.SendMessage("Rune installed into " + _color.Yellow("yellow") + " slot #" + (slots.FilledYellowSlots + 1));
                }
                else
                {
                    usePrismatic = true;
                }
                break;
            }

            if (usePrismatic)
            {
                string prismaticText = _rune.PrismaticString();
                targetItem.SetLocalInt("RUNIC_SLOT_PRISMATIC_" + (slots.FilledPrismaticSlots + 1), runeID);
                targetItem.SetLocalString("RUNIC_SLOT_PRISMATIC_DESC_" + (slots.FilledPrismaticSlots + 1), description);
                player.SendMessage("Rune installed into " + prismaticText + " slot #" + (slots.FilledPrismaticSlots + 1));
            }

            targetItem.RecommendedLevel += levelIncrease;
            runeItem.Destroy();

            SkillType skillType;

            if (_item.ArmorBaseItemTypes.Contains(targetItem.BaseItemType))
            {
                skillType = SkillType.Armorsmith;
            }
            else if (_item.WeaponBaseItemTypes.Contains(targetItem.BaseItemType))
            {
                skillType = SkillType.Weaponsmith;
            }
            else
            {
                return;
            }

            PCSkill pcSkill = _skill.GetPCSkill(player, skillType);
            int     xp      = (int)_skill.CalculateRegisteredSkillLevelAdjustedXP(400, runeLevel, pcSkill.Rank);

            _skill.GiveSkillXP(player, skillType, xp);
        }
Пример #18
0
        public void DoPerkUpgrade(NWPlayer oPC, int perkID)
        {
            Data.Entities.Perk perk   = _db.Perks.Single(x => x.PerkID == perkID);
            PCPerk             pcPerk = _db.PCPerks.SingleOrDefault(x => x.PlayerID == oPC.GlobalID && x.PerkID == perkID);
            PlayerCharacter    player = _db.PlayerCharacters.Single(x => x.PlayerID == oPC.GlobalID);

            if (CanPerkBeUpgraded(perk, pcPerk, player))
            {
                if (pcPerk == null)
                {
                    pcPerk = new PCPerk();
                    DateTime dt = DateTime.UtcNow;
                    pcPerk.AcquiredDate = dt;
                    pcPerk.PerkID       = perk.PerkID;
                    pcPerk.PlayerID     = oPC.GlobalID;
                    pcPerk.PerkLevel    = 0;

                    _db.PCPerks.Add(pcPerk);
                }

                PerkLevel nextPerkLevel = FindPerkLevel(perk.PerkLevels, pcPerk.PerkLevel + 1);
                if (nextPerkLevel == null)
                {
                    return;
                }

                pcPerk.PerkLevel++;
                player.UnallocatedSP -= nextPerkLevel.Price;

                _db.SaveChanges();

                // If a perk is activatable, create the item on the PC.
                // Remove any existing cast spell unique power properties and add the correct one based on the DB flag.
                if (!string.IsNullOrWhiteSpace(perk.ItemResref))
                {
                    if (_.GetIsObjectValid(_.GetItemPossessedBy(oPC.Object, perk.ItemResref)) == FALSE)
                    {
                        NWItem spellItem = NWItem.Wrap(_.CreateItemOnObject(perk.ItemResref, oPC.Object));
                        spellItem.IsCursed = true;
                        spellItem.SetLocalInt("ACTIVATION_PERK_ID", perk.PerkID);

                        foreach (ItemProperty ipCur in spellItem.ItemProperties)
                        {
                            int ipType    = _.GetItemPropertyType(ipCur);
                            int ipSubType = _.GetItemPropertySubType(ipCur);
                            if (ipType == ITEM_PROPERTY_CAST_SPELL &&
                                (ipSubType == IP_CONST_CASTSPELL_UNIQUE_POWER ||
                                 ipSubType == IP_CONST_CASTSPELL_UNIQUE_POWER_SELF_ONLY ||
                                 ipSubType == IP_CONST_CASTSPELL_ACTIVATE_ITEM))
                            {
                                _.RemoveItemProperty(spellItem.Object, ipCur);
                            }
                        }

                        ItemProperty ip;
                        if (perk.IsTargetSelfOnly)
                        {
                            ip = _.ItemPropertyCastSpell(IP_CONST_CASTSPELL_UNIQUE_POWER_SELF_ONLY, IP_CONST_CASTSPELL_NUMUSES_UNLIMITED_USE);
                        }
                        else
                        {
                            ip = _.ItemPropertyCastSpell(IP_CONST_CASTSPELL_UNIQUE_POWER, IP_CONST_CASTSPELL_NUMUSES_UNLIMITED_USE);
                        }

                        _biowareXP2.IPSafeAddItemProperty(spellItem, ip, 0.0f, AddItemPropertyPolicy.ReplaceExisting, false, false);
                    }

                    _.SetName(_.GetItemPossessedBy(oPC.Object, perk.ItemResref), perk.Name + " (Lvl. " + pcPerk.PerkLevel + ")");
                }

                oPC.SendMessage(_color.Green("Perk Purchased: " + perk.Name + " (Lvl. " + pcPerk.PerkLevel + ")"));

                IPerk perkScript = App.ResolveByInterface <IPerk>("Perk." + perk.JavaScriptName);

                if (perkScript == null)
                {
                    return;
                }
                perkScript.OnPurchased(oPC, pcPerk.PerkLevel);
            }
            else
            {
                oPC.FloatingText(_color.Red("You cannot purchase the perk at this time."));
            }
        }
Пример #19
0
        public bool Run(params object[] args)
        {
            NWPlayer    oPC           = (_.GetLastDisturbed());
            NWItem      item          = (_.GetInventoryDisturbItem());
            NWPlaceable container     = (Object.OBJECT_SELF);
            int         disturbType   = _.GetInventoryDisturbType();
            var         structureID   = new Guid(container.GetLocalString("PC_BASE_STRUCTURE_ID"));
            var         structure     = _data.Single <PCBaseStructure>(x => x.ID == structureID);
            var         baseStructure = _data.Get <BaseStructure>(structure.BaseStructureID);
            int         itemLimit     = baseStructure.Storage + structure.StructureBonus;

            int    itemCount  = container.InventoryItems.Count();
            string itemResref = item.Resref;

            if (disturbType == INVENTORY_DISTURB_TYPE_ADDED)
            {
                if (_.GetHasInventory(item) == TRUE)
                {
                    item.SetLocalInt("RETURNING_ITEM", TRUE);
                    _item.ReturnItem(oPC, item);
                    oPC.SendMessage(_color.Red("Containers cannot currently be stored inside banks."));
                    return(false);
                }

                if (itemCount > itemLimit)
                {
                    _item.ReturnItem(oPC, item);
                    oPC.SendMessage(_color.Red("No more items can be placed inside."));
                }
                else if (item.BaseItemType == BASE_ITEM_GOLD)
                {
                    _item.ReturnItem(oPC, item);
                    oPC.SendMessage(_color.Red("Credits cannot be placed inside."));
                }
                else
                {
                    PCBaseStructureItem itemEntity = new PCBaseStructureItem
                    {
                        ItemName          = item.Name,
                        ItemResref        = itemResref,
                        ItemTag           = item.Tag,
                        PCBaseStructureID = structureID,
                        ItemGlobalID      = item.GlobalID.ToString(),
                        ItemObject        = _serialization.Serialize(item)
                    };
                    _data.SubmitDataChange(itemEntity, DatabaseActionType.Insert);
                }
            }
            else if (disturbType == INVENTORY_DISTURB_TYPE_REMOVED)
            {
                if (item.GetLocalInt("RETURNING_ITEM") == TRUE)
                {
                    item.DeleteLocalInt("RETURNING_ITEM");
                }
                else
                {
                    var dbItem = _data.Single <PCBaseStructureItem>(x => x.ItemGlobalID == item.GlobalID.ToString());
                    _data.SubmitDataChange(dbItem, DatabaseActionType.Delete);
                }
            }

            oPC.SendMessage(_color.White("Item Limit: " + itemCount + " / ") + _color.Red(itemLimit.ToString()));

            return(true);
        }
Пример #20
0
        public static void CalculateEffectiveStats(NWPlayer player, NWItem item)
        {
            if (item == null || !item.IsValid || !player.IsPlayer || player.IsDMPossessed || player.IsDM || !player.IsInitializedAsPlayer)
            {
                return;
            }

            // Calculating effective stats can be expensive, so we cache it on the item.
            SkillType skill;

            if (item.BaseItemType == BaseItem.Amulet || item.BaseItemType == BaseItem.Ring)
            {
                var forceArmor = SkillService.GetPCSkill(player, (int)SkillType.ForceArmor);
                var lightArmor = SkillService.GetPCSkill(player, (int)SkillType.LightArmor);
                var heavyArmor = SkillService.GetPCSkill(player, (int)SkillType.HeavyArmor);
                var highest    = forceArmor.Rank;
                skill = SkillType.ForceArmor;

                if (lightArmor.Rank > highest)
                {
                    highest = lightArmor.Rank;
                    skill   = SkillType.LightArmor;
                }
                if (heavyArmor.Rank > highest)
                {
                    skill = SkillType.HeavyArmor;
                }
            }
            else
            {
                skill = ItemService.GetSkillTypeForItem(item);
            }

            var rank = DataService.PCSkill.GetByPlayerIDAndSkillID(player.GlobalID, (int)skill).Rank;

            using (new Profiler("PlayerStatService::ApplyStatChanges::GetPlayerItemEffectiveStats::ItemLoop::CalculateEffectiveStats"))
            {
                // Only scale cooldown recovery if it's a bonus. Penalties remain regardless of skill level difference.
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_COOLDOWN_RECOVERY", item.CooldownRecovery > 0
                    ? CalculateAdjustedValue(item.CooldownRecovery, item.RecommendedLevel, rank, 1)
                    : item.CooldownRecovery);

                item.SetLocalFloat("STAT_EFFECTIVE_LEVEL_ENMITY_RATE", CalculateAdjustedValue(0.01f * item.EnmityRate, item.RecommendedLevel, rank, 0.00f));

                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_LUCK_BONUS", CalculateAdjustedValue(item.LuckBonus, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_MEDITATE_BONUS", CalculateAdjustedValue(item.MeditateBonus, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_REST_BONUS", CalculateAdjustedValue(item.RestBonus, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_MEDICINE_BONUS", CalculateAdjustedValue(item.MedicineBonus, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_HP_REGEN_BONUS", CalculateAdjustedValue(item.HPRegenBonus, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_FP_REGEN_BONUS", CalculateAdjustedValue(item.FPRegenBonus, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_WEAPONSMITH_BONUS", CalculateAdjustedValue(item.CraftBonusWeaponsmith, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_COOKING_BONUS", CalculateAdjustedValue(item.CraftBonusCooking, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_ENGINEERING_BONUS", CalculateAdjustedValue(item.CraftBonusEngineering, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_FABRICATION_BONUS", CalculateAdjustedValue(item.CraftBonusFabrication, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_ARMORSMITH_BONUS", CalculateAdjustedValue(item.CraftBonusArmorsmith, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_HARVESTING_BONUS", CalculateAdjustedValue(item.HarvestingBonus, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_PILOTING_BONUS", CalculateAdjustedValue(item.PilotingBonus, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_SCAVENGING_BONUS", CalculateAdjustedValue(item.ScavengingBonus, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_SNEAK_ATTACK_BONUS", CalculateAdjustedValue(item.SneakAttackBonus, item.RecommendedLevel, rank, 0));

                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_STRENGTH_BONUS", CalculateAdjustedValue(item.StrengthBonus, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_DEXTERITY_BONUS", CalculateAdjustedValue(item.DexterityBonus, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_CONSTITUTION_BONUS", CalculateAdjustedValue(item.ConstitutionBonus, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_WISDOM_BONUS", CalculateAdjustedValue(item.WisdomBonus, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_INTELLIGENCE_BONUS", CalculateAdjustedValue(item.IntelligenceBonus, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_CHARISMA_BONUS", CalculateAdjustedValue(item.CharismaBonus, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_HP_BONUS", CalculateAdjustedValue(item.HPBonus, item.RecommendedLevel, rank, 0));
                item.SetLocalInt("STAT_EFFECTIVE_LEVEL_FP_BONUS", CalculateAdjustedValue(item.FPBonus, item.RecommendedLevel, rank, 0));
            }
        }
Пример #21
0
        public void Main()
        {
            NWPlayer    oPC           = (_.GetLastDisturbed());
            NWItem      item          = (_.GetInventoryDisturbItem());
            NWPlaceable container     = (NWGameObject.OBJECT_SELF);
            int         disturbType   = _.GetInventoryDisturbType();
            var         structureID   = new Guid(container.GetLocalString("PC_BASE_STRUCTURE_ID"));
            var         structure     = DataService.PCBaseStructure.GetByID(structureID);
            var         baseStructure = DataService.BaseStructure.GetByID(structure.BaseStructureID);
            int         itemLimit     = baseStructure.Storage + structure.StructureBonus;

            int    itemCount  = container.InventoryItems.Count();
            string itemResref = item.Resref;

            if (disturbType == _.INVENTORY_DISTURB_TYPE_ADDED)
            {
                if (_.GetHasInventory(item) == _.TRUE)
                {
                    item.SetLocalInt("RETURNING_ITEM", _.TRUE);
                    ItemService.ReturnItem(oPC, item);
                    oPC.SendMessage(ColorTokenService.Red("Containers cannot currently be stored inside banks."));
                    return;
                }

                if (itemCount > itemLimit)
                {
                    ItemService.ReturnItem(oPC, item);
                    oPC.SendMessage(ColorTokenService.Red("No more items can be placed inside."));
                }
                else if (item.BaseItemType == _.BASE_ITEM_GOLD)
                {
                    ItemService.ReturnItem(oPC, item);
                    oPC.SendMessage(ColorTokenService.Red("Credits cannot be placed inside."));
                }
                else
                {
                    PCBaseStructureItem itemEntity = new PCBaseStructureItem
                    {
                        ItemName          = item.Name,
                        ItemResref        = itemResref,
                        ItemTag           = item.Tag,
                        PCBaseStructureID = structureID,
                        ItemGlobalID      = item.GlobalID.ToString(),
                        ItemObject        = SerializationService.Serialize(item)
                    };
                    DataService.SubmitDataChange(itemEntity, DatabaseActionType.Insert);
                    MessageHub.Instance.Publish(new OnStoreStructureItem(oPC, itemEntity));
                }
            }
            else if (disturbType == _.INVENTORY_DISTURB_TYPE_REMOVED)
            {
                if (item.GetLocalInt("RETURNING_ITEM") == _.TRUE)
                {
                    item.DeleteLocalInt("RETURNING_ITEM");
                }
                else
                {
                    var dbItem = DataService.PCBaseStructureItem.GetByItemGlobalID(item.GlobalID.ToString());
                    DataService.SubmitDataChange(dbItem, DatabaseActionType.Delete);
                    MessageHub.Instance.Publish(new OnRemoveStructureItem(oPC, dbItem));
                }
            }

            oPC.SendMessage(ColorTokenService.White("Item Limit: " + itemCount + " / ") + ColorTokenService.Red(itemLimit.ToString()));
        }
Пример #22
0
        private static void ProcessVersion1LightsaberItem(NWItem item)
        {
            // Lightsaber appearances have changed because they're now considered training foils.
            // Depending on the type of lightsaber, modify the name, appearance and other details of the item.
            int baseItemType;

            // Appearance strings were built by running NWNXItem.GetEntireItemAppearance on the new design.
            // Then the result was copied over to here. Unfortunately, setting each individual part's graphic didn't work
            // so I used this instead.
            string appearanceString;

            switch (item.Resref)
            {
            // Blue lightsabers
            case "lightsaber_b":
            case "lightsaber_1":
            case "lightsaber_2":
            case "lightsaber_3":
            case "lightsaber_4":
                baseItemType     = 1; // 1 = Longsword
                appearanceString = "000000000000FBFBD300000000000000000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
                break;

            // Red Lightsabers
            case "lightsaber_r_b":
            case "lightsaber_r_1":
            case "lightsaber_r_2":
            case "lightsaber_r_3":
            case "lightsaber_r_4":
                baseItemType     = 1; // 1 = Longsword
                appearanceString = "000000000000FBFBD500000000000000000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
                break;

            // Green Lightsabers
            case "lightsaber_g_b":
            case "lightsaber_g_1":
            case "lightsaber_g_2":
            case "lightsaber_g_3":
            case "lightsaber_g_4":
                baseItemType     = 1; // 1 = Longsword
                appearanceString = "000000000000FBFBD400000000000000000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
                break;

            // Yellow Lightsabers
            case "lightsaber_y_b":
            case "lightsaber_y_1":
            case "lightsaber_y_2":
            case "lightsaber_y_3":
            case "lightsaber_y_4":
                baseItemType     = 1; // 1 = Longsword
                appearanceString = "000000000000FBFBB500000000000000000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
                // Also give a VFX item property for yellow sabers.
                var ip = _.ItemPropertyVisualEffect(_.ITEM_VISUAL_HOLY);
                BiowareXP2.IPSafeAddItemProperty(item, ip, 0.0f, AddItemPropertyPolicy.ReplaceExisting, false, false);
                break;

            default: return;
            }


            NWNXItem.SetBaseItemType(item, baseItemType);
            NWNXItem.RestoreItemAppearance(item, appearanceString);

            item.SetLocalInt("LIGHTSABER", _.TRUE);
            item.Name = item.Name.Replace("Lightsaber", "Training Foil").Replace("Saberstaff", "Training Foil Staff");
        }