Ejemplo n.º 1
0
        private void HandleBlueprintListPageResponse(int responseID)
        {
            DialogResponse response    = GetResponseByID("BlueprintListPage", responseID);
            int            blueprintID = (int)response.CustomData;

            if (blueprintID == -1)
            {
                ChangePage("CraftCategoriesPage");
                return;
            }

            var model = CraftService.GetPlayerCraftingData(GetPC());

            model.Blueprint        = CraftService.GetBlueprintByID(blueprintID);
            model.BlueprintID      = blueprintID;
            model.PlayerSkillRank  = SkillService.GetPCSkillRank(GetPC(), model.Blueprint.SkillID);
            model.MainMinimum      = model.Blueprint.MainMinimum;
            model.MainMaximum      = model.Blueprint.MainMaximum;
            model.SecondaryMinimum = model.Blueprint.SecondaryMinimum;
            model.SecondaryMaximum = model.Blueprint.SecondaryMaximum;
            model.TertiaryMinimum  = model.Blueprint.TertiaryMinimum;
            model.TertiaryMaximum  = model.Blueprint.TertiaryMaximum;

            string header = CraftService.BuildBlueprintHeader(GetPC(), blueprintID, false);

            SetPageHeader("BlueprintDetailsPage", header);
            ChangePage("BlueprintDetailsPage");
        }
Ejemplo n.º 2
0
        private float CalculateEquipmentBonus(NWPlayer player, SkillType skillType)
        {
            var   effectiveStats = PlayerStatService.GetPlayerItemEffectiveStats(player);
            int   equipmentBonus = 0;
            float multiplier     = 0.5f;
            int   atmosphere     = CraftService.CalculateAreaAtmosphereBonus(player.Area);

            if (atmosphere >= 75)
            {
                multiplier = 0.7f;
            }
            else if (atmosphere >= 25)
            {
                multiplier = 0.6f;
            }

            switch (skillType)
            {
            case SkillType.Armorsmith: equipmentBonus = effectiveStats.Armorsmith; break;

            case SkillType.Weaponsmith: equipmentBonus = effectiveStats.Weaponsmith; break;

            case SkillType.Cooking: equipmentBonus = effectiveStats.Cooking; break;

            case SkillType.Engineering: equipmentBonus = effectiveStats.Engineering; break;

            case SkillType.Fabrication: equipmentBonus = effectiveStats.Fabrication; break;

            case SkillType.Medicine: equipmentBonus = effectiveStats.Medicine; break;
            }

            return(equipmentBonus * multiplier); // +0.5%, +0.6%, or +0.7% per equipment bonus
        }
Ejemplo n.º 3
0
        private void LoadCraftPage(int blueprintID)
        {
            var model = CraftService.GetPlayerCraftingData(GetPC());

            model.BlueprintID = blueprintID;
            SwitchConversation("CraftItem");
        }
Ejemplo n.º 4
0
        private string ProcessPropertyDetails(int amount, string componentName, string propertyName, int maxBonuses, float levelsPerBonus = 1.0f)
        {
            var    player  = GetPC();
            string result  = string.Empty;
            int    penalty = 0;

            while (amount > 0)
            {
                if (amount >= maxBonuses)
                {
                    int levelIncrease    = (int)(maxBonuses * levelsPerBonus);
                    int chanceToTransfer = CraftService.CalculateReassemblyChance(player, penalty);
                    result  += componentName + " (+" + maxBonuses + " " + propertyName + ") [RL: " + levelIncrease + "] " + GetChanceColor(chanceToTransfer) + "\n";
                    penalty += (maxBonuses * 5);
                    amount  -= maxBonuses;
                }
                else
                {
                    int levelIncrease    = (int)(amount * levelsPerBonus);
                    int chanceToTransfer = CraftService.CalculateReassemblyChance(player, penalty);
                    result += componentName + " (+" + amount + " " + propertyName + ") [RL: " + levelIncrease + "] " + GetChanceColor(chanceToTransfer) + "\n";
                    break;
                }
            }

            return(result);
        }
Ejemplo n.º 5
0
        public override void Back(NWPlayer player, string beforeMovePage, string afterMovePage)
        {
            var model = CraftService.GetPlayerCraftingData(player);

            model.IsConfirmingReassemble = false;
            SetResponseText("SalvagePage", 1, "Reassemble Component(s)");
        }
Ejemplo n.º 6
0
        private void HandleRemoveItem()
        {
            NWPlayer    oPC     = (_.GetLastDisturbed());
            NWItem      oItem   = (_.GetInventoryDisturbItem());
            NWPlaceable device  = (Object.OBJECT_SELF);
            NWPlaceable storage = (_.GetObjectByTag("craft_temp_store"));
            var         model   = CraftService.GetPlayerCraftingData(oPC);

            if (oPC.IsBusy)
            {
                ItemService.ReturnItem(device, oItem);
                oPC.SendMessage("You are too busy right now.");
                return;
            }

            if (oItem.Resref == "cft_confirm")
            {
                oItem.Destroy();
                device.DestroyAllInventoryItems();
                device.IsLocked          = false;
                model.IsAccessingStorage = false;
                DialogService.StartConversation(oPC, device, "CraftItem");
                return;
            }

            List <NWItem> items = null;

            switch (model.Access)
            {
            case CraftingAccessType.MainComponent:
                items = model.MainComponents;
                break;

            case CraftingAccessType.SecondaryComponent:
                items = model.SecondaryComponents;
                break;

            case CraftingAccessType.TertiaryComponent:
                items = model.TertiaryComponents;
                break;

            case CraftingAccessType.Enhancement:
                items = model.EnhancementComponents;
                break;
            }

            NWItem copy     = storage.InventoryItems.SingleOrDefault(x => x.GlobalID == oItem.GlobalID);
            NWItem listItem = items?.SingleOrDefault(x => x.GlobalID == oItem.GlobalID);

            if (listItem == null || copy == null || !copy.IsValid)
            {
                return;
            }

            copy.Destroy();
            items.Remove(listItem);
        }
Ejemplo n.º 7
0
        private bool CheckValidity(NWPlaceable forge, NWPlayer pc, NWItem item)
        {
            if (pc.IsBusy)
            {
                ReturnItemToPC(pc, item, "You are too busy.");
                return(false);
            }

            if (_.GetIsObjectValid(forge.GetLocalObject("FORGE_USER")) == _.TRUE)
            {
                ReturnItemToPC(pc, item, "This forge is currently in use. Please wait...");
                return(false);
            }

            string[] allowed =
            {
                "power_core",
                "raw_veldite",
                "raw_scordspar",
                "raw_plagionite",
                "raw_keromber",
                "raw_jasioclase",
                "raw_hemorgite",
                "raw_ochne",
                "raw_croknor",
                "raw_arkoxit",
                "raw_bisteiss"
            };

            if (!allowed.Contains(item.Resref))
            {
                ReturnItemToPC(pc, item, "Only power cores and raw materials may be placed inside.");
                return(false);
            }

            int level = CraftService.GetIngotLevel(item.Resref);
            int rank  = SkillService.GetPCSkillRank(pc, SkillType.Harvesting);

            int delta = rank - level;

            if (delta <= -4)
            {
                ReturnItemToPC(pc, item, "You do not have enough skill to refine this material.");
                return(false);
            }

            int pcPerkLevel  = PerkService.GetCreaturePerkLevel(pc, PerkType.Refining);
            int orePerkLevel = CraftService.GetIngotPerkLevel(item.Resref);

            if (pcPerkLevel < orePerkLevel)
            {
                ReturnItemToPC(pc, item, "You do not have the perk necessary to refine this material.");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 8
0
        private void SalvagePageResponses(int responseID)
        {
            var player = GetPC();
            var model  = CraftService.GetPlayerCraftingData(player);

            switch (responseID)
            {
            case 1:     // Reassemble Component(s)

                NWItem fuel = _.GetItemPossessedBy(player, "ass_power");
                // Look for reassembly fuel in the player's inventory.
                if (!fuel.IsValid)
                {
                    player.SendMessage(ColorTokenService.Red("You must have a 'Reassembly Fuel Cell' in your inventory in order to start this process."));
                    return;
                }

                if (model.IsConfirmingReassemble)
                {
                    // Calculate delay, fire off delayed event, and show timing bar.
                    float delay = CraftService.CalculateCraftingDelay(player, (int)SkillType.Harvesting);
                    NWNXPlayer.StartGuiTimingBar(player, delay, string.Empty);
                    var @event = new OnReassembleComplete(player, model.SerializedSalvageItem, model.SalvageComponentTypeID);
                    player.DelayEvent(delay, @event);

                    // Make the player play an animation.
                    player.AssignCommand(() =>
                    {
                        _.ClearAllActions();
                        _.ActionPlayAnimation(ANIMATION_LOOPING_GET_MID, 1.0f, delay);
                    });

                    // Show sparks halfway through the process.
                    _.DelayCommand(1.0f * (delay / 2.0f), () =>
                    {
                        _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectVisualEffect(VFX_COM_BLOOD_SPARK_MEDIUM), NWGameObject.OBJECT_SELF);
                    });

                    // Immobilize the player while crafting.
                    Effect immobilize = _.EffectCutsceneImmobilize();
                    immobilize = _.TagEffect(immobilize, "CRAFTING_IMMOBILIZATION");
                    _.ApplyEffectToObject(DURATION_TYPE_PERMANENT, immobilize, player);

                    // Clear the temporary crafting data and end this conversation.
                    model.SerializedSalvageItem = string.Empty;
                    EndConversation();
                }
                else
                {
                    model.IsConfirmingReassemble = true;
                    SetResponseText("SalvagePage", 1, "CONFIRM REASSEMBLE COMPONENT(S)");
                }
                break;
            }
        }
Ejemplo n.º 9
0
        private void OpenScrapperInventory()
        {
            var         model     = CraftService.GetPlayerCraftingData(GetPC());
            NWPlaceable container = _.CreateObject(OBJECT_TYPE_PLACEABLE, "cft_scrapper", GetPC().Location);

            container.IsLocked       = false;
            model.IsAccessingStorage = true;

            GetPC().AssignCommand(() => _.ActionInteractObject(container.Object));
            EndConversation();
        }
Ejemplo n.º 10
0
        private void MainPageResponses(int responseID)
        {
            var            player   = GetPC();
            var            model    = CraftService.GetPlayerCraftingData(player);
            DialogResponse response = GetResponseByID("MainPage", responseID);

            model.SalvageComponentTypeID = (int)response.CustomData;

            LoadSalvagePage();
            ChangePage("SalvagePage");
        }
Ejemplo n.º 11
0
        public override void EndDialog()
        {
            var model = CraftService.GetPlayerCraftingData(GetPC());

            if (model.IsAccessingStorage)
            {
                return;
            }

            CraftService.ClearPlayerCraftingData(GetPC());
        }
Ejemplo n.º 12
0
        public bool Run(params object[] args)
        {
            NWPlaceable device = (Object.OBJECT_SELF);
            NWPlayer    oPC    = (_.GetLastOpenedBy());
            var         model  = CraftService.GetPlayerCraftingData(oPC);

            if (model.Access != CraftingAccessType.None)
            {
                NWItem        menuItem     = (_.CreateItemOnObject("cft_confirm", device.Object));
                NWPlaceable   storage      = (_.GetObjectByTag("craft_temp_store"));
                var           storageItems = storage.InventoryItems.ToList();
                List <NWItem> list         = null;

                if (model.Access == CraftingAccessType.MainComponent)
                {
                    menuItem.Name = "Confirm Main Components";
                    list          = model.MainComponents;
                }
                else if (model.Access == CraftingAccessType.SecondaryComponent)
                {
                    menuItem.Name = "Confirm Secondary Components";
                    list          = model.SecondaryComponents;
                }
                else if (model.Access == CraftingAccessType.TertiaryComponent)
                {
                    menuItem.Name = "Confirm Tertiary Components";
                    list          = model.TertiaryComponents;
                }
                else if (model.Access == CraftingAccessType.Enhancement)
                {
                    menuItem.Name = "Confirm Enhancement Components";
                    list          = model.EnhancementComponents;
                }

                if (list == null)
                {
                    oPC.FloatingText("Error locating component list. Notify an admin.");
                    return(false);
                }

                foreach (var item in list)
                {
                    NWItem storageItem = storageItems.Single(x => x.GlobalID == item.GlobalID);
                    _.CopyItem(storageItem.Object, device.Object, _.TRUE);
                }

                oPC.FloatingText("Place the components inside the container and then click the item named '" + menuItem.Name + "' to continue.");
            }

            device.IsLocked = true;
            return(true);
        }
Ejemplo n.º 13
0
        private void LoadSalvagePage()
        {
            var         player        = GetPC();
            var         model         = CraftService.GetPlayerCraftingData(player);
            NWPlaceable tempStorage   = _.GetObjectByTag("TEMP_ITEM_STORAGE");
            var         item          = SerializationService.DeserializeItem(model.SerializedSalvageItem, tempStorage);
            var         componentType = DataService.ComponentType.GetByID(model.SalvageComponentTypeID);
            string      header        = ColorTokenService.Green("Item: ") + item.Name + "\n\n";

            header += "Reassembling this item will create the following " + ColorTokenService.Green(componentType.Name) + " component(s). Chance to create depends on your perks, skills, and harvesting bonus on items.\n\n";

            // Always create one item with zero bonuses.
            header += componentType.Name + " (No Bonuses) [RL: 0] " + GetChanceColor(100) + "\n";

            // Now check specific custom properties which are stored as local variables on the item.
            header += ProcessPropertyDetails(item.HarvestingBonus, componentType.Name, "Harvesting Bonus", 3);
            header += ProcessPropertyDetails(item.PilotingBonus, componentType.Name, "Piloting Bonus", 3);
            header += ProcessPropertyDetails(item.ScanningBonus, componentType.Name, "Scanning Bonus", 3);
            header += ProcessPropertyDetails(item.ScavengingBonus, componentType.Name, "Scavenging Bonus", 3);
            header += ProcessPropertyDetails(item.CooldownRecovery, componentType.Name, "Cooldown Recovery", 3);
            header += ProcessPropertyDetails(item.CraftBonusArmorsmith, componentType.Name, "Armorsmith", 3);
            header += ProcessPropertyDetails(item.CraftBonusWeaponsmith, componentType.Name, "Weaponsmith", 3);
            header += ProcessPropertyDetails(item.CraftBonusCooking, componentType.Name, "Cooking", 3);
            header += ProcessPropertyDetails(item.CraftBonusEngineering, componentType.Name, "Engineering", 3);
            header += ProcessPropertyDetails(item.CraftBonusFabrication, componentType.Name, "Fabrication", 3);
            header += ProcessPropertyDetails(item.HPBonus, componentType.Name, "HP", 5, 0.5f);
            header += ProcessPropertyDetails(item.FPBonus, componentType.Name, "FP", 5, 0.5f);
            header += ProcessPropertyDetails(item.EnmityRate, componentType.Name, "Enmity", 3);
            header += ProcessPropertyDetails(item.LuckBonus, componentType.Name, "Luck", 3);
            header += ProcessPropertyDetails(item.MeditateBonus, componentType.Name, "Meditate", 3);
            header += ProcessPropertyDetails(item.RestBonus, componentType.Name, "Rest", 3);
            header += ProcessPropertyDetails(item.MedicineBonus, componentType.Name, "Medicine", 3);
            header += ProcessPropertyDetails(item.HPRegenBonus, componentType.Name, "HP Regen", 3);
            header += ProcessPropertyDetails(item.FPRegenBonus, componentType.Name, "FP Regen", 3);
            header += ProcessPropertyDetails(item.BaseAttackBonus, componentType.Name, "Base Attack Bonus", 3, 6f);
            header += ProcessPropertyDetails(item.StructureBonus, componentType.Name, "Structure Bonus", 3);
            header += ProcessPropertyDetails(item.SneakAttackBonus, componentType.Name, "Sneak Attack", 3);
            header += ProcessPropertyDetails(item.DamageBonus, componentType.Name, "Damage", 3);
            header += ProcessPropertyDetails(item.StrengthBonus, componentType.Name, "STR", 3);
            header += ProcessPropertyDetails(item.DexterityBonus, componentType.Name, "DEX", 3);
            header += ProcessPropertyDetails(item.ConstitutionBonus, componentType.Name, "CON", 3);
            header += ProcessPropertyDetails(item.WisdomBonus, componentType.Name, "WIS", 3);
            header += ProcessPropertyDetails(item.IntelligenceBonus, componentType.Name, "INT", 3);
            header += ProcessPropertyDetails(item.CharismaBonus, componentType.Name, "CHA", 3);
            header += ProcessPropertyDetails(item.DurationBonus, componentType.Name, "Duration", 3);


            SetPageHeader("SalvagePage", header);

            // Remove the temporary copy from the game world.
            item.Destroy();
        }
Ejemplo n.º 14
0
        private void LoadBlueprintListPage(int categoryID)
        {
            NWObject device   = GetDialogTarget();
            int      deviceID = device.GetLocalInt("CRAFT_DEVICE_ID");

            List <CraftBlueprint> blueprints = CraftService.GetPCBlueprintsByDeviceAndCategoryID(GetPC().GlobalID, deviceID, categoryID);

            ClearPageResponses("BlueprintListPage");
            foreach (CraftBlueprint bp in blueprints)
            {
                AddResponseToPage("BlueprintListPage", bp.Quantity + "x " + bp.ItemName, bp.IsActive, bp.ID);
            }
        }
Ejemplo n.º 15
0
        public override void Initialize()
        {
            Model vm = GetDialogCustomData <Model>();

            vm.CraftCategories = CraftService.GetCategoriesAvailableToPC(GetPC().GlobalID);

            foreach (CraftBlueprintCategory category in vm.CraftCategories)
            {
                AddResponseToPage("CraftCategoriesPage", category.Name, true, category.ID);
            }

            SetDialogCustomData(vm);
        }
Ejemplo n.º 16
0
        private void BuildMainPageOptions()
        {
            var  model              = CraftService.GetPlayerCraftingData(GetPC());
            int  maxEnhancements    = model.PlayerPerkLevel / 2;
            bool canAddEnhancements = model.Blueprint.EnhancementSlots > 0 && maxEnhancements > 0;

            AddResponseToPage("MainPage", "Examine Base Item");
            AddResponseToPage("MainPage", "Create Item", model.CanBuildItem);
            AddResponseToPage("MainPage", "Select Main Components");
            AddResponseToPage("MainPage", "Select Secondary Components", model.Blueprint.SecondaryMinimum > 0);
            AddResponseToPage("MainPage", "Select Tertiary Components", model.Blueprint.TertiaryMinimum > 0);
            AddResponseToPage("MainPage", "Select Enhancement Components", canAddEnhancements);

            AddResponseToPage("MainPage", "Change Blueprint");
        }
Ejemplo n.º 17
0
        public bool Run(params object[] args)
        {
            if (_.GetInventoryDisturbType() != _.INVENTORY_DISTURB_TYPE_ADDED)
            {
                return(false);
            }

            NWPlayer    player = _.GetLastDisturbed();
            NWPlaceable device = Object.OBJECT_SELF;
            NWItem      item   = _.GetInventoryDisturbItem();

            // Check the item type to see if it's valid.
            if (!IsValidItemType(item))
            {
                ItemService.ReturnItem(player, item);
                player.SendMessage("You cannot reassemble this item.");
                return(false);
            }

            // Only crafted items can be reassembled.
            if (string.IsNullOrWhiteSpace(item.GetLocalString("CRAFTER_PLAYER_ID")))
            {
                ItemService.ReturnItem(player, item);
                player.SendMessage("Only crafted items may be reassembled.");
                return(false);
            }

            // DMs cannot reassemble because they don't have the necessary DB records.
            if (player.IsDM)
            {
                ItemService.ReturnItem(player, item);
                player.SendMessage("DMs cannot reassemble items at this time.");
                return(false);
            }

            // Serialize the item into a string and store it into the temporary data for this player. Destroy the physical item.
            var model = CraftService.GetPlayerCraftingData(player);

            model.SerializedSalvageItem = SerializationService.Serialize(item);
            item.Destroy();

            // Start the Molecular Reassembly conversation.
            DialogService.StartConversation(player, device, "MolecularReassembly");

            return(true);
        }
Ejemplo n.º 18
0
        private void HandleCraftCategoriesPageResponse(int responseID)
        {
            Model vm = GetDialogCustomData <Model>();

            ClearPageResponses("BlueprintListPage");
            DialogResponse response   = GetResponseByID("CraftCategoriesPage", responseID);
            int            categoryID = (int)response.CustomData;

            vm.CraftBlueprints = CraftService.GetPCBlueprintsByCategoryID(GetPC().GlobalID, categoryID);

            foreach (CraftBlueprint bp in vm.CraftBlueprints)
            {
                AddResponseToPage("BlueprintListPage", bp.ItemName, true, bp.ID);
            }

            ChangePage("BlueprintListPage");
        }
Ejemplo n.º 19
0
        private void SalvagePageResponses(int responseID)
        {
            var player = GetPC();
            var model  = CraftService.GetPlayerCraftingData(player);

            switch (responseID)
            {
            case 1:     // Reassemble Component(s)
                if (model.IsConfirmingReassemble)
                {
                    // Calculate delay, fire off delayed event, and show timing bar.
                    float delay = CraftService.CalculateCraftingDelay(player, (int)SkillType.Harvesting);
                    NWNXPlayer.StartGuiTimingBar(player, delay, string.Empty);
                    player.DelayEvent <ReassembleComplete>(delay, player, model.SerializedSalvageItem, model.SalvageComponentTypeID);

                    // Make the player play an animation.
                    player.AssignCommand(() =>
                    {
                        _.ClearAllActions();
                        _.ActionPlayAnimation(ANIMATION_LOOPING_GET_MID, 1.0f, delay);
                    });

                    // Show sparks halfway through the process.
                    _.DelayCommand(1.0f * (delay / 2.0f), () =>
                    {
                        _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectVisualEffect(VFX_COM_BLOOD_SPARK_MEDIUM), Object.OBJECT_SELF);
                    });

                    // Immobilize the player while crafting.
                    Effect immobilize = _.EffectCutsceneImmobilize();
                    immobilize = _.TagEffect(immobilize, "CRAFTING_IMMOBILIZATION");
                    _.ApplyEffectToObject(DURATION_TYPE_PERMANENT, immobilize, player);

                    // Clear the temporary crafting data and end this conversation.
                    model.SerializedSalvageItem = string.Empty;
                    EndConversation();
                }
                else
                {
                    model.IsConfirmingReassemble = true;
                    SetResponseText("SalvagePage", 1, "CONFIRM REASSEMBLE COMPONENT(S)");
                }
                break;
            }
        }
Ejemplo n.º 20
0
        private void OpenDeviceInventory()
        {
            var         model  = CraftService.GetPlayerCraftingData(GetPC());
            NWPlaceable device = GetDevice();

            device.IsLocked          = false;
            model.IsAccessingStorage = true;

            _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_USED, string.Empty);
            _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_OPEN, "script_2");
            _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_CLOSED, "script_3");
            _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_INVENTORYDISTURBED, "script_4");

            device.SetLocalString("SCRIPT_2", "Placeable.CraftingDevice.OnOpened");
            device.SetLocalString("SCRIPT_3", "Placeable.CraftingDevice.OnClosed");
            device.SetLocalString("SCRIPT_4", "Placeable.CraftingDevice.OnDisturbed");

            GetPC().AssignCommand(() => _.ActionInteractObject(device.Object));
            EndConversation();
        }
Ejemplo n.º 21
0
        public bool Run(params object[] args)
        {
            // Should only fire when a player walks away from the device.
            // Clean up temporary data and return all items placed inside.
            NWPlayer    player = (_.GetLastClosedBy());
            NWPlaceable device = (Object.OBJECT_SELF);
            var         model  = CraftService.GetPlayerCraftingData(player);

            device.DestroyAllInventoryItems();
            device.IsLocked          = false;
            model.IsAccessingStorage = false;

            foreach (var item in model.MainComponents)
            {
                _.CopyItem(item.Object, player.Object, _.TRUE);
                item.Destroy();
            }
            foreach (var item in model.SecondaryComponents)
            {
                _.CopyItem(item.Object, player.Object, _.TRUE);
                item.Destroy();
            }
            foreach (var item in model.TertiaryComponents)
            {
                _.CopyItem(item.Object, player.Object, _.TRUE);
                item.Destroy();
            }
            foreach (var item in model.EnhancementComponents)
            {
                _.CopyItem(item.Object, player.Object, _.TRUE);
                item.Destroy();
            }

            _.SetEventScript(device.Object, _.EVENT_SCRIPT_PLACEABLE_ON_USED, "jvm_script_1");
            _.SetEventScript(device.Object, _.EVENT_SCRIPT_PLACEABLE_ON_OPEN, string.Empty);
            _.SetEventScript(device.Object, _.EVENT_SCRIPT_PLACEABLE_ON_CLOSED, string.Empty);
            _.SetEventScript(device.Object, _.EVENT_SCRIPT_PLACEABLE_ON_INVENTORYDISTURBED, string.Empty);
            player.Data.Remove("CRAFTING_MODEL");
            return(true);
        }
Ejemplo n.º 22
0
        public void Main()
        {
            // Should only fire when a player walks away from the device.
            // Clean up temporary data and return all items placed inside.
            NWPlayer    player = (_.GetLastClosedBy());
            NWPlaceable device = (_.OBJECT_SELF);
            var         model  = CraftService.GetPlayerCraftingData(player);

            device.DestroyAllInventoryItems();
            device.IsLocked          = false;
            model.IsAccessingStorage = false;

            foreach (var item in model.MainComponents)
            {
                _.CopyItem(item.Object, player.Object, true);
                item.Destroy();
            }
            foreach (var item in model.SecondaryComponents)
            {
                _.CopyItem(item.Object, player.Object, true);
                item.Destroy();
            }
            foreach (var item in model.TertiaryComponents)
            {
                _.CopyItem(item.Object, player.Object, true);
                item.Destroy();
            }
            foreach (var item in model.EnhancementComponents)
            {
                _.CopyItem(item.Object, player.Object, true);
                item.Destroy();
            }

            _.SetEventScript(device.Object, EventScript.Placeable_OnUsed, "script_1");
            _.SetEventScript(device.Object, EventScript.Placeable_OnOpen, string.Empty);
            _.SetEventScript(device.Object, EventScript.Placeable_OnClosed, string.Empty);
            _.SetEventScript(device.Object, EventScript.Placeable_OnInventoryDisturbed, string.Empty);
            player.Data.Remove("CRAFTING_MODEL");
        }
Ejemplo n.º 23
0
        private void LoadCategoryResponses()
        {
            NWPlaceable device   = (NWPlaceable)GetDialogTarget();
            int         deviceID = device.GetLocalInt("CRAFT_DEVICE_ID");
            List <CraftBlueprintCategory> categories = CraftService.GetCategoriesAvailableToPCByDeviceID(GetPC().GlobalID, deviceID);

            ClearPageResponses("MainPage");

            var lastBlueprintId = GetPC().GetLocalInt("LAST_CRAFTED_BLUEPRINT_ID_" + deviceID);
            var bp = CraftService.GetBlueprintByID(lastBlueprintId);

            if (bp != null)
            {
                AddResponseToPage("MainPage", bp.Quantity + "x " + bp.ItemName, bp.IsActive, new Tuple <int, Type>(bp.ID, typeof(CraftBlueprint)));
            }

            AddResponseToPage("MainPage", "Scrap Item");

            foreach (CraftBlueprintCategory category in categories)
            {
                AddResponseToPage("MainPage", category.Name, category.IsActive, new Tuple <int, Type>(category.ID, typeof(CraftBlueprintCategory)));
            }
        }
Ejemplo n.º 24
0
        private int ProcessProperty(int amount, int maxBonuses, ComponentBonusType bonus, float levelsPerBonus = 1.0f)
        {
            string resref  = _componentType.ReassembledResref;
            int    penalty = 0;
            int    luck    = PerkService.GetPCPerkLevel(_player, PerkType.Lucky) + (_playerItemStats.Luck / 3);
            int    xp      = 0;

            ItemPropertyUnpacked bonusIP = new ItemPropertyUnpacked
            {
                Property       = (int)CustomItemPropertyType.ComponentBonus,
                SubType        = (int)bonus,
                CostTable      = 62,
                CostTableValue = 0,
                Param1         = 255,
                Param1Value    = 0,
                UsesPerDay     = 255,
                ChanceToAppear = 100,
                IsUseable      = true,
                SpellID        = -1
            };

            while (amount > 0)
            {
                int chanceToTransfer = CraftService.CalculateReassemblyChance(_player, penalty);
                // Roll to see if the item can be created.
                bool success = RandomService.Random(0, 100) <= chanceToTransfer;

                // Do a lucky roll if we failed the first time.
                if (!success && luck > 0 && RandomService.Random(0, 100) <= luck)
                {
                    _player.SendMessage("Lucky reassemble!");
                    success = true;
                }

                if (amount >= maxBonuses)
                {
                    if (success)
                    {
                        int levelIncrease = (int)(maxBonuses * levelsPerBonus);
                        // Roll succeeded. Create item.
                        bonusIP.CostTableValue = maxBonuses;
                        ItemProperty bonusIPPacked = NWNXItemProperty.PackIP(bonusIP);
                        NWItem       item          = _.CreateItemOnObject(resref, _player);
                        item.RecommendedLevel = levelIncrease;
                        BiowareXP2.IPSafeAddItemProperty(item, bonusIPPacked, 0.0f, AddItemPropertyPolicy.ReplaceExisting, true, false);

                        xp += (150 * maxBonuses + RandomService.Random(0, 5));
                    }
                    else
                    {
                        _player.SendMessage(ColorTokenService.Red("You failed to create a component. (+" + maxBonuses + ")"));
                        xp += (50 + RandomService.Random(0, 5));
                    }
                    // Penalty to chance increases regardless if item was created or not.
                    penalty += (maxBonuses * 5);
                    amount  -= maxBonuses;
                }
                else
                {
                    if (success)
                    {
                        int levelIncrease = (int)(amount * levelsPerBonus);
                        bonusIP.CostTableValue = amount;
                        ItemProperty bonusIPPacked = NWNXItemProperty.PackIP(bonusIP);
                        NWItem       item          = _.CreateItemOnObject(resref, _player);
                        item.RecommendedLevel = levelIncrease;
                        BiowareXP2.IPSafeAddItemProperty(item, bonusIPPacked, 0.0f, AddItemPropertyPolicy.ReplaceExisting, true, false);

                        xp += (150 * amount + RandomService.Random(0, 5));
                    }
                    else
                    {
                        _player.SendMessage(ColorTokenService.Red("You failed to create a component. (+" + amount + ")"));
                        xp += (50 + RandomService.Random(0, 5));
                    }
                    break;
                }
            }

            return(xp);
        }
Ejemplo n.º 25
0
        private static void RunServer()
        {
            Data.Data.DataPath = "data/";

            Stopwatch sw = Stopwatch.StartNew();

            AppDomain.CurrentDomain.UnhandledException += UnhandledException;

            Console.WriteLine("----===== Tera-Project C# GameServer Emulator =====----\n\n");
            Console.WriteLine("Starting Game Server!\n"
                              + "-------------------------------------------");

            TcpServer = new TcpServer("*", Config.GetServerPort(), Config.GetServerMaxCon());
            Connection.SendAllThread.Start();

            OpCodes.Init();
            Console.WriteLine("OpCodes - Revision 1725 initialized!\n"
                              + "-------------------------------------------\n");

            #region global_components

            //services
            FeedbackService    = new FeedbackService();
            AccountService     = new AccountService();
            PlayerService      = new PlayerService();
            MapService         = new MapService();
            ChatService        = new ChatService();
            VisibleService     = new VisibleService();
            ControllerService  = new ControllerService();
            CraftService       = new CraftService();
            ItemService        = new ItemService();
            AiService          = new AiService();
            GeoService         = new GeoService();
            StatsService       = new StatsService();
            ObserverService    = new ObserverService();
            AreaService        = new AreaService();
            InformerService    = new InformerService();
            TeleportService    = new TeleportService();
            PartyService       = new PartyService();
            SkillsLearnService = new SkillsLearnService();
            CraftLearnService  = new CraftLearnService();
            GuildService       = new GuildService();
            EmotionService     = new EmotionService();
            RelationService    = new RelationService();
            DuelService        = new DuelService();
            StorageService     = new StorageService();
            TradeService       = new TradeService();
            MountService       = new MountService();

            //engines
            ActionEngine = new ActionEngine.ActionEngine();
            AdminEngine  = new AdminEngine.AdminEngine();
            SkillEngine  = new SkillEngine.SkillEngine();
            QuestEngine  = new QuestEngine.QuestEngine();

            #endregion

            GlobalLogic.ServerStart("SERVER=" + Config.GetDatabaseHost() + ";DATABASE=" + Config.GetDatabaseName() + ";UID=" + Config.GetDatabaseUser() + ";PASSWORD="******";PORT=" + Config.GetDatabasePort() + ";charset=utf8");

            Console.WriteLine("-------------------------------------------\n"
                              + "Loading Tcp Service.\n"
                              + "-------------------------------------------");
            TcpServer.BeginListening();

            try
            {
                ServiceApplication = ScsServiceBuilder.CreateService(new ScsTcpEndPoint(23232));
                ServiceApplication.AddService <IInformerService, InformerService>((InformerService)InformerService);
                ServiceApplication.Start();
                Log.Info("InformerService started at *:23232.");

                var webservices = new ServiceManager();
                webservices.Run();
            }
            catch (Exception ex)
            {
                Log.ErrorException("InformerService can not be started.", ex);
            }

            sw.Stop();
            Console.WriteLine("-------------------------------------------");
            Console.WriteLine("           Server start in {0}", (sw.ElapsedMilliseconds / 1000.0).ToString("0.00s"));
            Console.WriteLine("-------------------------------------------");
        }
Ejemplo n.º 26
0
        public override void Initialize()
        {
            ToggleBackButton(false);

            var model  = CraftService.GetPlayerCraftingData(GetPC());
            var device = GetDevice();

            // Entering the conversation for the first time from the blueprint selection menu.
            if (!model.IsInitialized)
            {
                model.IsInitialized   = true;
                model.Blueprint       = CraftService.GetBlueprintByID(model.BlueprintID);
                model.PlayerSkillRank = SkillService.GetPCSkillRank(GetPC(), model.Blueprint.SkillID);

                switch ((SkillType)model.Blueprint.SkillID)
                {
                case SkillType.Armorsmith:
                    model.PlayerPerkLevel = PerkService.GetCreaturePerkLevel(GetPC(), PerkType.ArmorBlueprints);
                    break;

                case SkillType.Engineering:
                    model.PlayerPerkLevel = PerkService.GetCreaturePerkLevel(GetPC(), PerkType.EngineeringBlueprints);
                    break;

                case SkillType.Weaponsmith:
                    model.PlayerPerkLevel = PerkService.GetCreaturePerkLevel(GetPC(), PerkType.WeaponBlueprints);
                    break;

                case SkillType.Fabrication:
                    model.PlayerPerkLevel = PerkService.GetCreaturePerkLevel(GetPC(), PerkType.FabricationBlueprints);
                    break;

                case SkillType.Medicine:
                    model.PlayerPerkLevel = PerkService.GetCreaturePerkLevel(GetPC(), PerkType.MedicalBlueprints);
                    break;

                case SkillType.Lightsaber:
                    model.PlayerPerkLevel = PerkService.GetCreaturePerkLevel(GetPC(), PerkType.LightsaberBlueprints);
                    // Lightsabers do not have Optimisation or Efficiency perks.
                    break;

                default:
                    model.PlayerPerkLevel = 0;
                    break;
                }
                GetDevice().IsLocked   = true;
                model.MainMinimum      = model.Blueprint.MainMinimum;
                model.SecondaryMinimum = model.Blueprint.SecondaryMinimum;
                model.TertiaryMinimum  = model.Blueprint.TertiaryMinimum;

                model.MainMaximum      = model.Blueprint.MainMaximum;
                model.SecondaryMaximum = model.Blueprint.SecondaryMaximum > 0 ? model.Blueprint.SecondaryMaximum : 0;
                model.TertiaryMaximum  = model.Blueprint.TertiaryMaximum > 0 ? model.Blueprint.TertiaryMaximum : 0;

                if (model.MainMinimum <= 0)
                {
                    model.MainMinimum = 1;
                }
                if (model.SecondaryMinimum <= 0 && model.Blueprint.SecondaryMinimum > 0)
                {
                    model.SecondaryMinimum = 1;
                }
                if (model.TertiaryMinimum <= 0 && model.Blueprint.TertiaryMinimum > 0)
                {
                    model.TertiaryMinimum = 1;
                }
            }
            // Otherwise returning from accessing the device's inventory.
            else
            {
                model.Access = CraftingAccessType.None;

                _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_USED, "script_1");
                _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_OPEN, string.Empty);
                _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_CLOSED, string.Empty);
                _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_INVENTORYDISTURBED, string.Empty);
            }


            SetPageHeader("MainPage", CraftService.BuildBlueprintHeader(GetPC(), true));
            BuildMainPageOptions();
        }
Ejemplo n.º 27
0
        private static void RunServer()
        {
            //Start ServerStartTime
            Stopwatch serverStartStopwatch = Stopwatch.StartNew();

            AppDomain.CurrentDomain.UnhandledException += UnhandledException;

            //CheckServerMode
            CheckServerMode();

            //ConsoleOutput-Infos
            PrintServerLicence();
            PrintServerInfo();

            //Initialize TcpServer
            TcpServer = new TcpServer("*", Configuration.Network.GetServerPort(), Configuration.Network.GetServerMaxCon());
            Connection.SendAllThread.Start();

            //Initialize Server OpCodes
            OpCodes.Init();
            Console.WriteLine("----------------------------------------------------------------------------\n"
                              + "---===== OpCodes - Revision: " + OpCodes.Version + " EU initialized!");

            //Global Services
            #region global_components
            //Services
            FeedbackService    = new FeedbackService();
            AccountService     = new AccountService();
            PlayerService      = new PlayerService();
            MapService         = new MapService();
            ChatService        = new ChatService();
            VisibleService     = new VisibleService();
            ControllerService  = new ControllerService();
            CraftService       = new CraftService();
            ItemService        = new ItemService();
            AiService          = new AiService();
            GeoService         = new GeoService();
            StatsService       = new StatsService();
            ObserverService    = new ObserverService();
            AreaService        = new AreaService();
            TeleportService    = new TeleportService();
            PartyService       = new PartyService();
            SkillsLearnService = new SkillsLearnService();
            CraftLearnService  = new CraftLearnService();
            GuildService       = new GuildService();
            EmotionService     = new EmotionService();
            RelationService    = new RelationService();
            DuelService        = new DuelService();
            StorageService     = new StorageService();
            TradeService       = new TradeService();
            MountService       = new MountService();

            //Engines
            ActionEngine = new ActionEngine.ActionEngine();
            AdminEngine  = new AdminEngine.AdminEngine();
            SkillEngine  = new SkillEngine.SkillEngine();
            QuestEngine  = new QuestEngine.QuestEngine();
            #endregion

            //Set SqlDatabase Connection
            GlobalLogic.ServerStart("SERVER=" + DAOManager.MySql_Host + ";DATABASE=" + DAOManager.MySql_Database + ";UID=" + DAOManager.MySql_User + ";PASSWORD="******";PORT=" + DAOManager.MySql_Port + ";charset=utf8");
            Console.ForegroundColor = ConsoleColor.Gray;

            //Start Tcp-Server Listening
            Console.WriteLine("----------------------------------------------------------------------------\n"
                              + "---===== Loading GameServer Service.\n"
                              + "----------------------------------------------------------------------------");
            TcpServer.BeginListening();

            //Stop ServerStartTime
            serverStartStopwatch.Stop();
            Console.WriteLine("----------------------------------------------------------------------------");
            Console.WriteLine("---===== GameServer start in {0}", (serverStartStopwatch.ElapsedMilliseconds / 1000.0).ToString("0.00s"));
            Console.WriteLine("----------------------------------------------------------------------------");
        }
Ejemplo n.º 28
0
        private void HandleMainPageResponses(int responseID)
        {
            var         model  = CraftService.GetPlayerCraftingData(GetPC());
            NWPlaceable device = GetDevice();

            switch (responseID)
            {
            case 1:     // Examine Base Item
                CraftBlueprint entity        = CraftService.GetBlueprintByID(model.BlueprintID);
                NWPlaceable    tempContainer = (_.GetObjectByTag("craft_temp_store"));
                NWItem         examineItem   = (_.CreateItemOnObject(entity.ItemResref, tempContainer.Object));
                GetPC().AssignCommand(() => _.ActionExamine(examineItem.Object));
                examineItem.Destroy(0.1f);
                break;

            case 2:     // Create item
                if (!model.CanBuildItem)
                {
                    GetPC().FloatingText("You are missing some required components.");
                    return;
                }

                int effectiveLevel = CraftService.CalculatePCEffectiveLevel(GetPC(), model.PlayerSkillRank, (SkillType)model.Blueprint.SkillID);
                int difficulty     = effectiveLevel - model.AdjustedLevel;

                if (difficulty <= -5)
                {
                    GetPC().FloatingText("It's impossible to make this item because its level is too high. Use lower-level components to reduce the level and difficulty.");
                    return;
                }

                CraftService.CraftItem(GetPC(), device);
                model.IsAccessingStorage = true;
                EndConversation();
                break;

            case 3:     // Select main components
                model.Access = CraftingAccessType.MainComponent;
                OpenDeviceInventory();
                break;

            case 4:     // Select secondary components
                model.Access = CraftingAccessType.SecondaryComponent;
                OpenDeviceInventory();
                break;

            case 5:     // Select tertiary components
                model.Access = CraftingAccessType.TertiaryComponent;
                OpenDeviceInventory();
                break;

            case 6:     // Select enhancement components
                model.Access = CraftingAccessType.Enhancement;
                OpenDeviceInventory();
                break;

            case 7:     // Back (return to blueprint selection)
                CraftService.ClearPlayerCraftingData(GetPC());
                SwitchConversation("CraftingDevice");
                break;
            }
        }
Ejemplo n.º 29
0
        private void LoadSalvagePage()
        {
            var         player        = GetPC();
            var         model         = CraftService.GetPlayerCraftingData(player);
            NWPlaceable tempStorage   = _.GetObjectByTag("TEMP_ITEM_STORAGE");
            var         item          = SerializationService.DeserializeItem(model.SerializedSalvageItem, tempStorage);
            var         componentType = DataService.Get <ComponentType>(model.SalvageComponentTypeID);
            string      header        = ColorTokenService.Green("Item: ") + item.Name + "\n\n";

            header += "Reassembling this item will create the following " + ColorTokenService.Green(componentType.Name) + " component(s). Chance to create depends on your perks, skills, and harvesting bonus on items.\n\n";

            // Always create one item with zero bonuses.
            header += componentType.Name + " (No Bonuses) [RL: 0] " + GetChanceColor(100) + "\n";

            // Start by checking attack bonus since we're not storing this value as a local variable on the item.
            foreach (var prop in item.ItemProperties)
            {
                int propTypeID = _.GetItemPropertyType(prop);
                if (propTypeID == ITEM_PROPERTY_ATTACK_BONUS)
                {
                    // Get the amount of Attack Bonus
                    int amount = _.GetItemPropertyCostTableValue(prop);
                    header += ProcessPropertyDetails(amount, componentType.Name, "Attack Bonus", 3);
                }
            }

            // Now check specific custom properties which are stored as local variables on the item.
            header += ProcessPropertyDetails(item.CustomAC, componentType.Name, "AC", 3);
            header += ProcessPropertyDetails(item.HarvestingBonus, componentType.Name, "Harvesting Bonus", 3);
            header += ProcessPropertyDetails(item.PilotingBonus, componentType.Name, "Piloting Bonus", 3);
            header += ProcessPropertyDetails(item.ScanningBonus, componentType.Name, "Scanning Bonus", 3);
            header += ProcessPropertyDetails(item.ScavengingBonus, componentType.Name, "Scavenging Bonus", 3);
            header += ProcessPropertyDetails(item.CastingSpeed, componentType.Name, "Activation Speed", 3);
            header += ProcessPropertyDetails(item.CraftBonusArmorsmith, componentType.Name, "Armorsmith", 3);
            header += ProcessPropertyDetails(item.CraftBonusWeaponsmith, componentType.Name, "Weaponsmith", 3);
            header += ProcessPropertyDetails(item.CraftBonusCooking, componentType.Name, "Cooking", 3);
            header += ProcessPropertyDetails(item.CraftBonusEngineering, componentType.Name, "Engineering", 3);
            header += ProcessPropertyDetails(item.CraftBonusFabrication, componentType.Name, "Fabrication", 3);
            header += ProcessPropertyDetails(item.HPBonus, componentType.Name, "HP", 5, 0.5f);
            header += ProcessPropertyDetails(item.FPBonus, componentType.Name, "FP", 5, 0.5f);
            header += ProcessPropertyDetails(item.EnmityRate, componentType.Name, "Enmity", 3);
            header += ProcessPropertyDetails(item.ForcePotencyBonus, componentType.Name, "Force Potency", 3);
            header += ProcessPropertyDetails(item.ForceAccuracyBonus, componentType.Name, "Force Accuracy", 3);
            header += ProcessPropertyDetails(item.ForceDefenseBonus, componentType.Name, "Force Defense", 3);
            header += ProcessPropertyDetails(item.ElectricalPotencyBonus, componentType.Name, "Electrical Potency", 3);
            header += ProcessPropertyDetails(item.MindPotencyBonus, componentType.Name, "Mind Potency", 3);
            header += ProcessPropertyDetails(item.LightPotencyBonus, componentType.Name, "Light Potency", 3);
            header += ProcessPropertyDetails(item.DarkPotencyBonus, componentType.Name, "Dark Potency", 3);
            header += ProcessPropertyDetails(item.ElectricalDefenseBonus, componentType.Name, "Electrical Defense", 3);
            header += ProcessPropertyDetails(item.MindDefenseBonus, componentType.Name, "Mind Defense", 3);
            header += ProcessPropertyDetails(item.LightDefenseBonus, componentType.Name, "Light Defense", 3);
            header += ProcessPropertyDetails(item.DarkDefenseBonus, componentType.Name, "Dark Defense", 3);
            header += ProcessPropertyDetails(item.LuckBonus, componentType.Name, "Luck", 3);
            header += ProcessPropertyDetails(item.MeditateBonus, componentType.Name, "Meditate", 3);
            header += ProcessPropertyDetails(item.RestBonus, componentType.Name, "Rest", 3);
            header += ProcessPropertyDetails(item.MedicineBonus, componentType.Name, "Medicine", 3);
            header += ProcessPropertyDetails(item.HPRegenBonus, componentType.Name, "HP Regen", 3);
            header += ProcessPropertyDetails(item.FPRegenBonus, componentType.Name, "FP Regen", 3);
            header += ProcessPropertyDetails(item.BaseAttackBonus, componentType.Name, "BAB", 3, 6);
            header += ProcessPropertyDetails(item.StructureBonus, componentType.Name, "Structure Bonus", 3);
            header += ProcessPropertyDetails(item.SneakAttackBonus, componentType.Name, "Sneak Attack", 3);
            header += ProcessPropertyDetails(item.DamageBonus, componentType.Name, "Damage", 3);
            header += ProcessPropertyDetails(item.StrengthBonus, componentType.Name, "STR", 3);
            header += ProcessPropertyDetails(item.DexterityBonus, componentType.Name, "DEX", 3);
            header += ProcessPropertyDetails(item.ConstitutionBonus, componentType.Name, "CON", 3);
            header += ProcessPropertyDetails(item.WisdomBonus, componentType.Name, "WIS", 3);
            header += ProcessPropertyDetails(item.IntelligenceBonus, componentType.Name, "INT", 3);
            header += ProcessPropertyDetails(item.CharismaBonus, componentType.Name, "CHA", 3);
            header += ProcessPropertyDetails(item.DurationBonus, componentType.Name, "Duration", 3);


            SetPageHeader("SalvagePage", header);

            // Remove the temporary copy from the game world.
            item.Destroy();
        }
Ejemplo n.º 30
0
        public override void EndDialog()
        {
            var player = GetPC();

            CraftService.ClearPlayerCraftingData(player);
        }