Exemplo n.º 1
0
        public string BuildBlueprintHeader(NWPlayer player, int blueprintID)
        {
            CraftBlueprint blueprint = _db.CraftBlueprints.Single(x => x.CraftBlueprintID == blueprintID);
            PCSkill        pcSkill   = _db.PCSkills.Single(x => x.PlayerID == player.GlobalID && x.SkillID == blueprint.SkillID);

            string header = _color.Green("Blueprint: ") + _color.White(blueprint.ItemName) + "\n\n";

            header += _color.Green("Skill: ") + _color.White(pcSkill.Skill.Name) + "\n";

            if (blueprint.CraftTierLevel > 0)
            {
                header += _color.Green("Required Tool Level: ") + blueprint.CraftTierLevel + "\n";
            }

            header += _color.Green("Difficulty: ") + CalculateDifficulty(pcSkill.Rank, blueprint.Level) + "\n\n";
            header += _color.Green("Components: ") + "\n\n";

            foreach (CraftBlueprintComponent component in blueprint.CraftBlueprintComponents)
            {
                string name = _item.GetNameByResref(component.ItemResref);
                header += _color.White(component.Quantity + "x " + name) + "\n";
            }

            return(header);
        }
Exemplo n.º 2
0
    public void EditCraftFromBlueprint(CraftBlueprint bp)
    {
        ClearCurrCraft();

        PlayerManager.instance.SetCraftInputEnabled(false);
        PlayerManager.instance.PlayerCraft        = null;
        PlayerManager.instance.playerCraftWasNull = true; //To prevent spawn menu from opening again

        currCraft = CraftBlueprint.SpawnCraftFromBlueprint(bp, transform.position, transform.eulerAngles);

        SmoothFollowCam camComp = PlayerManager.instance.cam;

        camComp.followTarget  = CamLookTarget;
        camComp.lookMode      = SmoothFollowCam.LookMode.ORBIT;
        camComp.freelook_xrot = 25;
        camComp.freelook_yrot = 0;
        camComp.rotation      = 45;
        camComp.zoom          = 1f;

        camRot = Vector2.zero;
        foreach (PhysPart part in currCraft.GetComponentsInChildren <PhysPart>())
        {
            MakePartEditorFriendly(part);
        }
        currCraft.rb.isKinematic = true;
        currCraft.enabled        = false;
    }
Exemplo n.º 3
0
 void FixedUpdate()
 {
     if (debug_CraftToSave != null)
     {
         debug_CraftBlueprint = CraftBlueprint.GetBlueprintFromCraft(debug_CraftToSave);
         debug_CraftToSave    = null;
     }
     if (debug_CraftBlueprint != null)
     {
         if (debug_SaveCraftBlueprint)
         {
             debug_SaveCraftBlueprint = false;
             CraftBlueprint.SaveToFile(debug_CraftBlueprint);
         }
         if (debug_LoadCraftBlueprint)
         {
             debug_LoadCraftBlueprint = false;
             debug_CraftBlueprint     = CraftBlueprint.LoadFromFileByName(debug_LoadCraftBlueprintFileName);
         }
         if (debug_SpawnCraftBlueprint)
         {
             CraftBlueprint.SpawnCraftFromBlueprint(debug_CraftBlueprint, Vector3.up * 10f, Vector3.zero);
             debug_SpawnCraftBlueprint = false;
         }
         if (debug_ForgetCraftBlueprint)
         {
             debug_ForgetCraftBlueprint = false;
             debug_CraftBlueprint       = null;
         }
     }
 }
Exemplo n.º 4
0
        public string BuildBlueprintHeader(NWPlayer player, int blueprintID)
        {
            CraftBlueprint blueprint = _db.CraftBlueprints.Single(x => x.CraftBlueprintID == blueprintID);
            PCSkill        pcSkill   = _db.PCSkills.Single(x => x.PlayerID == player.GlobalID && x.SkillID == blueprint.SkillID);

            string header = _color.Green("Blueprint: ") + _color.White(blueprint.ItemName) + "\n\n";

            header += _color.Green("Skill: ") + _color.White(pcSkill.Skill.Name) + "\n";

            header += _color.Green("Base Difficulty: ") + CalculateDifficulty(pcSkill.Rank, blueprint.BaseLevel) + "\n";
            header += _color.Green("Max Enhancement Slots: ") + blueprint.EnhancementSlots + "\n\n";

            header += _color.Green("Components: ") + "\n\n";

            header += _color.White(blueprint.MainMinimum + "x " + blueprint.MainComponentType.Name) + "\n";

            if (blueprint.SecondaryComponentTypeID > 0)
            {
                header += _color.White(blueprint.SecondaryMinimum + "x " + blueprint.SecondaryComponentType.Name) + "\n";
            }

            if (blueprint.TertiaryComponentTypeID > 0)
            {
                header += _color.White(blueprint.TertiaryMinimum + "x " + blueprint.TertiaryComponentType.Name) + "\n";
            }

            return(header);
        }
Exemplo n.º 5
0
        private void HandleBlueprintResponse(int responseID)
        {
            DialogResponse response = GetResponseByID("BlueprintPage", responseID);
            int            blueprintID;

            switch (responseID)
            {
            case 1:     // Examine item
                blueprintID = (int)response.CustomData[string.Empty];
                CraftBlueprint entity        = _craft.GetBlueprintByID(blueprintID);
                NWPlaceable    tempContainer = NWPlaceable.Wrap(_.GetObjectByTag("craft_temp_store"));
                NWItem         examineItem   = NWItem.Wrap(_.CreateItemOnObject(entity.ItemResref, tempContainer.Object));
                examineItem.Destroy();

                GetPC().AssignCommand(() => _.ActionExamine(examineItem.Object));
                break;

            case 2:     // Select Blueprint
                blueprintID = (int)response.CustomData[string.Empty];
                GetPC().SendMessage("Blueprint selected. Add necessary resources to the device and click the 'Craft Item' option.");

                NWPlaceable device = (NWPlaceable)GetDialogTarget();
                device.SetLocalInt("CRAFT_BLUEPRINT_ID", blueprintID);
                GetPC().AssignCommand(() => _.ActionInteractObject(device.Object));
                EndConversation();
                break;

            case 3:     // Back
                ChangePage("BlueprintListPage");
                break;
            }
        }
Exemplo n.º 6
0
        private void HandleBlueprintResponse(int responseID)
        {
            DialogResponse response = GetResponseByID("BlueprintPage", responseID);
            int            blueprintID;

            switch (responseID)
            {
            case 1:     // Examine item
                blueprintID = (int)response.CustomData[string.Empty];
                CraftBlueprint entity        = _craft.GetBlueprintByID(blueprintID);
                NWPlaceable    tempContainer = NWPlaceable.Wrap(_.GetObjectByTag("craft_temp_store"));
                NWItem         examineItem   = NWItem.Wrap(_.CreateItemOnObject(entity.ItemResref, tempContainer.Object));
                GetPC().AssignCommand(() => _.ActionExamine(examineItem.Object));
                examineItem.Destroy(0.1f);
                break;

            case 2:     // Craft this item
                blueprintID = (int)response.CustomData[string.Empty];
                GetPC().SetLocalInt("CRAFT_BLUEPRINT_ID", blueprintID);
                SwitchConversation("CraftItem");
                break;

            case 3:     // Back
                ChangePage("BlueprintListPage");
                break;
            }
        }
Exemplo n.º 7
0
        private void RunCreateItem(NWPlayer oPC, NWPlaceable device)
        {
            var model = GetPlayerCraftingData(oPC);

            CraftBlueprint blueprint = _db.CraftBlueprints.Single(x => x.CraftBlueprintID == model.BlueprintID);
            PCSkill        pcSkill   = _db.PCSkills.Single(x => x.PlayerID == oPC.GlobalID && x.SkillID == blueprint.SkillID);

            int   pcEffectiveLevel = CalculatePCEffectiveLevel(oPC, device, pcSkill.Rank);
            float chance           = CalculateBaseChanceToAddProperty(pcEffectiveLevel, model.AdjustedLevel);
            float equipmentBonus   = CalculateEquipmentBonus(oPC, (SkillType)blueprint.SkillID);

            var    craftedItems = new List <NWItem>();
            NWItem craftedItem  = NWItem.Wrap(_.CreateItemOnObject(blueprint.ItemResref, oPC.Object, blueprint.Quantity));

            craftedItem.IsIdentified = true;
            craftedItems.Add(craftedItem);

            // If item isn't stackable, loop through and create as many as necessary.
            if (craftedItem.StackSize < blueprint.Quantity)
            {
                for (int x = 2; x <= blueprint.Quantity; x++)
                {
                    craftedItem = NWItem.Wrap(_.CreateItemOnObject(blueprint.ItemResref, oPC.Object));
                    craftedItem.IsIdentified = true;
                    craftedItems.Add(craftedItem);
                }
            }

            foreach (var component in model.MainComponents)
            {
                ComponentBonusType bonus = ComponentBonusType.Unknown;
                foreach (var ip in component.ItemProperties)
                {
                    if (_.GetItemPropertyType(ip) == (int)CustomItemPropertyType.ComponentBonus)
                    {
                        bonus = (ComponentBonusType)_.GetItemPropertyCostTableValue(ip);
                    }
                }

                if (bonus == ComponentBonusType.Unknown)
                {
                    continue;
                }

                if (_random.RandomFloat() * 100.0f + equipmentBonus <= chance)
                {
                    foreach (var item in craftedItems)
                    {
                        ApplyComponentBonus(item, bonus);
                    }
                }
            }

            oPC.SendMessage("You created " + blueprint.Quantity + "x " + blueprint.ItemName + "!");
            float xp = _skill.CalculateRegisteredSkillLevelAdjustedXP(250, model.AdjustedLevel, pcSkill.Rank);

            _skill.GiveSkillXP(oPC, blueprint.SkillID, (int)xp);
            ClearPlayerCraftingData(oPC);
        }
Exemplo n.º 8
0
 public void SaveCurrCraft()
 {
     if (currCraft == null)
     {
         return;
     }
     CraftBlueprint.SaveToFile(GetBlueprintFromCurrCraft());
 }
Exemplo n.º 9
0
    public static string SaveToFile(CraftBlueprint bp)
    {
        string dir      = "crafts";
        string fileName = bp.craftName + ".bp";

        SaveLoadJSON.SaveObjToFile(bp, dir, fileName);
        return(SaveLoadJSON.GetFullPath(dir + "/" + fileName));
    }
Exemplo n.º 10
0
    public void SaveAndRespawn()
    {
        SaveCraft();
        CraftBlueprint.SpawnCraftFromBlueprint(savedCraft, transform.GetChild(0).position, transform.GetChild(0).transform.eulerAngles);

        transform.position = Vector3.down * 55555f;
        Destroy(gameObject);
        gameObject.SetActive(false);
    }
Exemplo n.º 11
0
        private void HandleMainPageResponses(int responseID)
        {
            var model = _craft.GetPlayerCraftingData(GetPC());
            NWPlaceable device = GetDevice();

            switch (responseID)
            {
                case 1: // Examine Base Item
                    CraftBlueprint entity = _craft.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 = _craft.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;
                    }

                    _craft.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)
                    _craft.ClearPlayerCraftingData(GetPC());
                    SwitchConversation("CraftingDevice");
                    break;
            }
        }
Exemplo n.º 12
0
    /// <param name="pathIsRelative">is the path relative to Application.persistentDataPath/saved/</param>
    public static CraftBlueprint LoadFromFile(string path, bool pathIsRelative)
    {
        CraftBlueprint bp = SaveLoadJSON.LoadObjFromFile <CraftBlueprint>(path, pathIsRelative);

        if (bp != null)
        {
            Debug.Log("Loaded Blueprint of '" + bp.craftName + "' from file at " + path);
        }
        return(bp);
    }
Exemplo n.º 13
0
 public override void OnCraftSelected(string fileName)
 {
     if (!Input.GetKey(KeyCode.LeftShift) || !allowEditing)
     {
         spawnMenu.SpawnSavedCraft(fileName);
     }
     else //If holding LShift, edit the craft (if allowed).
     {
         CraftEditor.instance.EditCraftFromBlueprint(CraftBlueprint.LoadFromFileByName(fileName));
     }
     spawnMenu.CloseMenu();
 }
Exemplo n.º 14
0
 public CraftBlueprint SaveCraft(bool overwriteCurrentSave = true)
 {
     if (overwriteCurrentSave)
     {
         savedCraft = CraftBlueprint.GetBlueprintFromCraft(GetComponent <MultipartPhysBody>());
         return(savedCraft);
     }
     else
     {
         return(CraftBlueprint.GetBlueprintFromCraft(GetComponent <MultipartPhysBody>()));
     }
 }
Exemplo n.º 15
0
        public void CraftItem(NWPlayer oPC, NWPlaceable device)
        {
            var            model     = GetPlayerCraftingData(oPC);
            CraftBlueprint blueprint = _db.CraftBlueprints.Single(x => x.CraftBlueprintID == model.BlueprintID);

            if (blueprint == null)
            {
                return;
            }

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

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

            oPC.IsBusy = true;

            float modifiedCraftDelay = CalculateCraftingDelay(oPC, blueprint.SkillID);

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

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

            oPC.DelayCommand(() =>
            {
                try
                {
                    RunCreateItem(oPC, device);
                    oPC.IsBusy = false;
                }
                catch (Exception ex)
                {
                    _error.LogError(ex);
                }
            }, modifiedCraftDelay);
        }
Exemplo n.º 16
0
        public void GetByID_OneItem_ReturnsCraftBlueprint()
        {
            // Arrange
            CraftBlueprint entity = new CraftBlueprint {
                ID = 1
            };

            // Act
            MessageHub.Instance.Publish(new OnCacheObjectSet <CraftBlueprint>(entity));

            // Assert
            Assert.AreNotSame(entity, _cache.GetByID(1));
        }
Exemplo n.º 17
0
        private void HandleCraftItem(NWPlayer oPC, NWPlaceable device)
        {
            int            blueprintID = device.GetLocalInt("CRAFT_BLUEPRINT_ID");
            int            deviceID    = device.GetLocalInt("CRAFT_DEVICE_ID");
            CraftBlueprint pcBlueprint = _craft.GetBlueprintKnownByPC(oPC.GlobalID, blueprintID, deviceID);

            if (pcBlueprint == null)
            {
                oPC.FloatingText(_color.Red("You do not know that blueprint."));
                return;
            }

            _craft.CraftItem(oPC, device, blueprintID);
        }
Exemplo n.º 18
0
        public void CraftItem(NWPlayer oPC, NWPlaceable device)
        {
            var            model     = GetPlayerCraftingData(oPC);
            CraftBlueprint blueprint = _data.Single <CraftBlueprint>(x => x.ID == model.BlueprintID);

            if (blueprint == null)
            {
                return;
            }

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

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

            oPC.IsBusy = true;

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

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

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

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

            oPC.DelayEvent <CraftCreateItem>(
                modifiedCraftDelay,
                oPC);
        }
Exemplo n.º 19
0
        public static void CraftItem(NWPlayer oPC, NWPlaceable device)
        {
            var            model     = GetPlayerCraftingData(oPC);
            CraftBlueprint blueprint = DataService.CraftBlueprint.GetByID(model.BlueprintID);

            if (blueprint == null)
            {
                return;
            }

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

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

            oPC.IsBusy = true;

            float modifiedCraftDelay = CalculateCraftingDelay(oPC, blueprint.SkillID);

            oPC.AssignCommand(() =>
            {
                _.ClearAllActions();
                _.ActionPlayAnimation(Animation.LoopingGetMid, 1.0f, modifiedCraftDelay);
            });
            _.DelayCommand(1.0f * (modifiedCraftDelay / 2.0f), () =>
            {
                _.ApplyEffectToObject(DurationType.Instant, _.EffectVisualEffect(VisualEffect.Vfx_Com_Blood_Spark_Medium), device.Object);
            });
            var immobilize = _.EffectCutsceneImmobilize();

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

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

            var @event = new OnCreateCraftedItem(oPC);

            oPC.DelayEvent(modifiedCraftDelay, @event);
        }
Exemplo n.º 20
0
    public CraftBlueprint GetBlueprintFromCurrCraft()
    {
        //ignore held part
        if (currPart != null)
        {
            currPart.transform.SetParent(null);
            currPart.DestroyPartLite();
        }

        MultipartPhysBody physBody = currCraft.GetComponent <MultipartPhysBody>();

        physBody.UpdatePhysParts(true);
        foreach (PhysPart p in physBody.Parts)
        {
            p.connections = CalculatePartConnections(p);
        }
        return(CraftBlueprint.GetBlueprintFromCraft(physBody));
    }
Exemplo n.º 21
0
        public void GetByID_TwoItems_ReturnsCorrectObject()
        {
            // Arrange
            CraftBlueprint entity1 = new CraftBlueprint {
                ID = 1
            };
            CraftBlueprint entity2 = new CraftBlueprint {
                ID = 2
            };

            // Act
            MessageHub.Instance.Publish(new OnCacheObjectSet <CraftBlueprint>(entity1));
            MessageHub.Instance.Publish(new OnCacheObjectSet <CraftBlueprint>(entity2));

            // Assert
            Assert.AreNotSame(entity1, _cache.GetByID(1));
            Assert.AreNotSame(entity2, _cache.GetByID(2));
        }
Exemplo n.º 22
0
    public static CraftBlueprint GetBlueprintFromCraft(MultipartPhysBody craft)
    {
        CraftBlueprint bp = new CraftBlueprint();

        bp.craftName = craft.name;

        //Generate parts list
        int i = 0;

        foreach (PhysPart part in craft.Parts)
        {
            //save part info
            PartBlueprint p = part.GetBlueprint();

            //Check if this is the origin part if originPartIndex isn't assigned yet. If it is the origin part, assign originPartIndex to reference it.
            if (bp.originPartIndex == -1 && part == craft.originPart)
            {
                bp.originPartIndex = i;
            }

            bp.parts.Add(p);
            i++;
        }

        //Generate part connections list now that we have all the parts.
        //We can use indices interchangably between the physical craft and the blueprint because the parts were added in the same order.
        int partIndex = 0;

        foreach (PhysPart part in craft.Parts)
        {
            foreach (PartConnection connection in part.connections)
            {
                ConnectionBlueprint c = new ConnectionBlueprint();
                c.fromIndex = partIndex; //set fromIndex to reference the part we are currently processing
                int toIndex = craft.Parts.IndexOf(connection.toPart);
                c.toIndex = toIndex;

                bp.connections.Add(c);
            }
            partIndex++;
        }

        return(bp);
    }
Exemplo n.º 23
0
        public void GetByID_RemovedItem_ReturnsCorrectObject()
        {
            // Arrange
            CraftBlueprint entity1 = new CraftBlueprint {
                ID = 1
            };
            CraftBlueprint entity2 = new CraftBlueprint {
                ID = 2
            };

            // Act
            MessageHub.Instance.Publish(new OnCacheObjectSet <CraftBlueprint>(entity1));
            MessageHub.Instance.Publish(new OnCacheObjectSet <CraftBlueprint>(entity2));
            MessageHub.Instance.Publish(new OnCacheObjectDeleted <CraftBlueprint>(entity1));

            // Assert
            Assert.Throws <KeyNotFoundException>(() => { _cache.GetByID(1); });
            Assert.AreNotSame(entity2, _cache.GetByID(2));
        }
Exemplo n.º 24
0
        public bool Run(params object[] args)
        {
            NWPlaceable device            = NWPlaceable.Wrap(Object.OBJECT_SELF);
            NWPlayer    oPC               = NWPlayer.Wrap(_.GetLastOpenedBy());
            int         blueprintSelected = device.GetLocalInt("CRAFT_BLUEPRINT_ID");

            _.CreateItemOnObject("cft_choose_bp", device.Object);
            if (blueprintSelected > 0)
            {
                CraftBlueprint entity = _craft.GetBlueprintByID(blueprintSelected);

                NWItem menuItem = NWItem.Wrap(_.CreateItemOnObject("cft_craft_item", device.Object));
                menuItem.Name = "Craft Item: " + entity.ItemName;

                oPC.SendMessage(_craft.BuildBlueprintHeader(oPC, blueprintSelected));
            }

            return(true);
        }
Exemplo n.º 25
0
        public void GetByID_NoItems_ThrowsKeyNotFoundException()
        {
            // Arrange
            CraftBlueprint entity1 = new CraftBlueprint {
                ID = 1
            };
            CraftBlueprint entity2 = new CraftBlueprint {
                ID = 2
            };

            // Act
            MessageHub.Instance.Publish(new OnCacheObjectSet <CraftBlueprint>(entity1));
            MessageHub.Instance.Publish(new OnCacheObjectSet <CraftBlueprint>(entity2));
            MessageHub.Instance.Publish(new OnCacheObjectDeleted <CraftBlueprint>(entity1));
            MessageHub.Instance.Publish(new OnCacheObjectDeleted <CraftBlueprint>(entity2));

            // Assert
            Assert.Throws <KeyNotFoundException>(() => { _cache.GetByID(1); });
            Assert.Throws <KeyNotFoundException>(() => { _cache.GetByID(2); });
        }
Exemplo n.º 26
0
    public static MultipartPhysBody SpawnCraftFromBlueprint(CraftBlueprint bp, Vector3 position, Vector3 rotation)
    {
        //Set up transform structure before adding any parts etc.
        Transform t = new GameObject(bp.craftName).transform; //Main craft

        t.position    = position;
        t.eulerAngles = rotation;
        t.SetParent(GameplayManager.GameplayTransform);
        Transform body = new GameObject("Body").transform; //Body (part holder)

        body.SetParent(t);
        body.localPosition = body.localEulerAngles = Vector3.zero;

        //Set up components
        t.gameObject.AddComponent <Rigidbody>();
        MultipartPhysBody craft = t.gameObject.AddComponent <MultipartPhysBody>();

        //Set up parts
        List <PhysPart> spawnedParts = new List <PhysPart>();

        foreach (PartBlueprint p in bp.parts)
        {
            PhysPart part = p.SpawnPart(body);
            spawnedParts.Add(part);
        }
        //Set up part connections
        foreach (ConnectionBlueprint c in bp.connections)
        {
            spawnedParts[c.fromIndex].connections.Add(new PartConnection(spawnedParts[c.toIndex], spawnedParts[c.fromIndex]));
        }

        //Disable input until it gets overriden by a system which is responsible for this (player spawning, AI spawning, etc.)
        craft.SetBalancerInputActive(false);

        return(craft);
    }
Exemplo n.º 27
0
        private void RunCreateItem(NWPlayer oPC, NWPlaceable device, int blueprintID)
        {
            NWPlaceable tempStorage = NWPlaceable.Wrap(device.GetLocalObject("CRAFT_TEMP_STORAGE"));
            NWItem      tools       = NWItem.Wrap(device.GetLocalObject("CRAFT_DEVICE_TOOLS"));

            CraftBlueprint blueprint = _db.CraftBlueprints.Single(x => x.CraftBlueprintID == blueprintID);
            PCSkill        pcSkill   = _db.PCSkills.Single(x => x.PlayerID == oPC.GlobalID && x.SkillID == blueprint.SkillID);

            int pcEffectiveLevel = CalculatePCEffectiveLevel(oPC, device, pcSkill.Rank);


            float chance = CalculateChanceToCreateItem(pcEffectiveLevel, blueprint.Level);
            float roll   = _random.RandomFloat() * 100.0f;
            float xpModifier;

            if (roll <= chance)
            {
                // Success!
                foreach (NWItem item in tempStorage.InventoryItems)
                {
                    item.Destroy();
                }

                NWItem craftedItem = NWItem.Wrap(_.CreateItemOnObject(blueprint.ItemResref, oPC.Object, blueprint.Quantity));
                craftedItem.IsIdentified = true;

                // If item isn't stackable, loop through and create as many as necessary.
                if (craftedItem.StackSize < blueprint.Quantity)
                {
                    for (int x = 2; x <= blueprint.Quantity; x++)
                    {
                        craftedItem = NWItem.Wrap(_.CreateItemOnObject(blueprint.ItemResref, oPC.Object));
                        craftedItem.IsIdentified = true;
                    }
                }

                oPC.SendMessage("You created " + blueprint.Quantity + "x " + blueprint.ItemName + "!");
                xpModifier = 1.0f;
            }
            else
            {
                // Failure...
                int chanceToLoseItems = 20;

                foreach (NWItem item in tempStorage.InventoryItems)
                {
                    if (_random.Random(100) > chanceToLoseItems)
                    {
                        _.CopyItem(item.Object, device.Object, TRUE);
                    }
                    item.Destroy();
                }

                oPC.SendMessage("You failed to create that item...");
                xpModifier = 0.2f;
            }

            float xp = _skill.CalculateSkillAdjustedXP(250, blueprint.Level, pcSkill.Rank) * xpModifier;

            tempStorage.Destroy();
            _skill.GiveSkillXP(oPC, blueprint.SkillID, (int)xp);

            if (tools.IsValid)
            {
                float min = 0.05f;
                float max = 0.1f;
                float reduceDurability = min + _random.RandomFloat() * (max - min);
                _durability.RunItemDecay(oPC, tools, reduceDurability);
            }

            if (_random.Random(100) + 1 <= 3)
            {
                _food.DecreaseHungerLevel(oPC, 1);
            }
        }
Exemplo n.º 28
0
 public void SpawnCraft()
 {
     CraftBlueprint.SpawnCraftFromBlueprint(Blueprint, transform.position, transform.eulerAngles);
 }
Exemplo n.º 29
0
        private void RunCreateItem(NWPlayer player)
        {
            foreach (var effect in player.Effects)
            {
                if (_.GetEffectTag(effect) == "CRAFTING_IMMOBILIZATION")
                {
                    _.RemoveEffect(player, effect);
                }
            }

            var model = CraftService.GetPlayerCraftingData(player);

            CraftBlueprint blueprint     = DataService.CraftBlueprint.GetByID(model.BlueprintID);
            BaseStructure  baseStructure = blueprint.BaseStructureID == null ? null : DataService.BaseStructure.GetByID(Convert.ToInt32(blueprint.BaseStructureID));
            PCSkill        pcSkill       = SkillService.GetPCSkill(player, blueprint.SkillID);

            int   pcEffectiveLevel = CraftService.CalculatePCEffectiveLevel(player, pcSkill.Rank, (SkillType)blueprint.SkillID);
            int   itemLevel        = model.AdjustedLevel;
            int   atmosphereBonus  = CraftService.CalculateAreaAtmosphereBonus(player.Area);
            float chance           = CalculateBaseChanceToAddProperty(pcEffectiveLevel, itemLevel, atmosphereBonus);
            float equipmentBonus   = CalculateEquipmentBonus(player, (SkillType)blueprint.SkillID);

            if (chance <= 1.0f)
            {
                player.FloatingText(ColorTokenService.Red("Critical failure! You don't have enough skill to create that item. All components were lost."));
                CraftService.ClearPlayerCraftingData(player, true);
                return;
            }

            int    luckyBonus   = PerkService.GetCreaturePerkLevel(player, PerkType.Lucky);
            var    craftedItems = new List <NWItem>();
            NWItem craftedItem  = (_.CreateItemOnObject(blueprint.ItemResref, player.Object, blueprint.Quantity));

            craftedItem.IsIdentified = true;
            craftedItems.Add(craftedItem);

            // If item isn't stackable, loop through and create as many as necessary.
            if (craftedItem.StackSize < blueprint.Quantity)
            {
                for (int x = 2; x <= blueprint.Quantity; x++)
                {
                    craftedItem = (_.CreateItemOnObject(blueprint.ItemResref, player.Object));
                    craftedItem.IsIdentified = true;
                    craftedItems.Add(craftedItem);
                }
            }

            // Recommended level gets set regardless if all item properties make it on the final product.
            // Also mark who crafted the item. This is later used for display on the item's examination event.
            foreach (var item in craftedItems)
            {
                item.RecommendedLevel = itemLevel < 0 ? 0 : itemLevel;
                item.SetLocalString("CRAFTER_PLAYER_ID", player.GlobalID.ToString());

                BaseService.ApplyCraftedItemLocalVariables(item, baseStructure);
            }

            if (RandomService.Random(1, 100) <= luckyBonus)
            {
                chance += RandomService.Random(1, luckyBonus);
            }

            int successAmount = 0;

            foreach (var component in model.MainComponents)
            {
                var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems);
                successAmount += result.Item1;
                chance         = result.Item2;
            }
            foreach (var component in model.SecondaryComponents)
            {
                var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems);
                successAmount += result.Item1;
                chance         = result.Item2;
            }
            foreach (var component in model.TertiaryComponents)
            {
                var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems);
                successAmount += result.Item1;
                chance         = result.Item2;
            }
            foreach (var component in model.EnhancementComponents)
            {
                var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems);
                successAmount += result.Item1;
                chance         = result.Item2;
            }

            // Structures gain increased durability based on the blueprint
            if (baseStructure != null)
            {
                foreach (var item in craftedItems)
                {
                    var maxDur = DurabilityService.GetMaxDurability(item);
                    maxDur += (float)baseStructure.Durability;
                    DurabilityService.SetMaxDurability(item, maxDur);
                    DurabilityService.SetDurability(item, maxDur);
                }
            }

            player.SendMessage("You created " + blueprint.Quantity + "x " + blueprint.ItemName + "!");
            int   baseXP = 750 + successAmount * RandomService.Random(1, 50);
            float xp     = SkillService.CalculateRegisteredSkillLevelAdjustedXP(baseXP, model.AdjustedLevel, pcSkill.Rank);

            bool exists = DataService.PCCraftedBlueprint.ExistsByPlayerIDAndCraftedBlueprintID(player.GlobalID, blueprint.ID);

            if (!exists)
            {
                xp = xp * 1.50f;
                player.SendMessage("You receive an XP bonus for crafting this item for the first time.");

                var pcCraftedBlueprint = new PCCraftedBlueprint
                {
                    CraftBlueprintID = blueprint.ID,
                    DateFirstCrafted = DateTime.UtcNow,
                    PlayerID         = player.GlobalID
                };

                DataService.SubmitDataChange(pcCraftedBlueprint, DatabaseActionType.Insert);
            }

            SkillService.GiveSkillXP(player, blueprint.SkillID, (int)xp);
            CraftService.ClearPlayerCraftingData(player, true);
            player.SetLocalInt("LAST_CRAFTED_BLUEPRINT_ID_" + blueprint.CraftDeviceID, blueprint.ID);
        }
Exemplo n.º 30
0
        private void RunCreateItem(NWPlayer player)
        {
            var model = _craft.GetPlayerCraftingData(player);

            CraftBlueprint blueprint     = _data.Single <CraftBlueprint>(x => x.ID == model.BlueprintID);
            BaseStructure  baseStructure = blueprint.BaseStructureID == null ? null : _data.Get <BaseStructure>(blueprint.BaseStructureID);
            PCSkill        pcSkill       = _skill.GetPCSkill(player, blueprint.SkillID);

            int   pcEffectiveLevel = _craft.CalculatePCEffectiveLevel(player, pcSkill.Rank, (SkillType)blueprint.SkillID);
            int   itemLevel        = model.AdjustedLevel;
            float chance           = CalculateBaseChanceToAddProperty(pcEffectiveLevel, itemLevel);
            float equipmentBonus   = CalculateEquipmentBonus(player, (SkillType)blueprint.SkillID);

            if (chance <= 1.0f)
            {
                player.FloatingText(_color.Red("Critical failure! You don't have enough skill to create that item. All components were lost."));
                _craft.ClearPlayerCraftingData(player, true);
                return;
            }

            int    luckyBonus   = _perk.GetPCPerkLevel(player, PerkType.Lucky);
            var    craftedItems = new List <NWItem>();
            NWItem craftedItem  = (_.CreateItemOnObject(blueprint.ItemResref, player.Object, blueprint.Quantity));

            craftedItem.IsIdentified = true;
            craftedItems.Add(craftedItem);

            // If item isn't stackable, loop through and create as many as necessary.
            if (craftedItem.StackSize < blueprint.Quantity)
            {
                for (int x = 2; x <= blueprint.Quantity; x++)
                {
                    craftedItem = (_.CreateItemOnObject(blueprint.ItemResref, player.Object));
                    craftedItem.IsIdentified = true;
                    craftedItems.Add(craftedItem);
                }
            }

            // Recommended level gets set regardless if all item properties make it on the final product.
            // Also mark who crafted the item. This is later used for display on the item's examination event.
            foreach (var item in craftedItems)
            {
                item.RecommendedLevel = itemLevel < 0 ? 0 : itemLevel;
                item.SetLocalString("CRAFTER_PLAYER_ID", player.GlobalID.ToString());

                _base.ApplyCraftedItemLocalVariables(item, baseStructure);
            }

            if (_random.Random(1, 100) <= luckyBonus)
            {
                chance += _random.Random(1, luckyBonus);
            }

            int successAmount = 0;

            foreach (var component in model.MainComponents)
            {
                var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems);
                successAmount += result.Item1;
                chance         = result.Item2;
            }
            foreach (var component in model.SecondaryComponents)
            {
                var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems);
                successAmount += result.Item1;
                chance         = result.Item2;
            }
            foreach (var component in model.TertiaryComponents)
            {
                var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems);
                successAmount += result.Item1;
                chance         = result.Item2;
            }
            foreach (var component in model.EnhancementComponents)
            {
                var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems);
                successAmount += result.Item1;
                chance         = result.Item2;
            }

            // Structures gain increased durability based on the blueprint
            if (baseStructure != null)
            {
                foreach (var item in craftedItems)
                {
                    var maxDur = _durability.GetMaxDurability(item);
                    maxDur += (float)baseStructure.Durability;
                    _durability.SetMaxDurability(item, maxDur);
                    _durability.SetDurability(item, maxDur);
                }
            }

            player.SendMessage("You created " + blueprint.Quantity + "x " + blueprint.ItemName + "!");
            int   baseXP = 250 + successAmount * _random.Random(1, 50);
            float xp     = _skill.CalculateRegisteredSkillLevelAdjustedXP(baseXP, model.AdjustedLevel, pcSkill.Rank);

            var pcCraftedBlueprint = _data.SingleOrDefault <PCCraftedBlueprint>(x => x.PlayerID == player.GlobalID && x.CraftBlueprintID == blueprint.ID);

            if (pcCraftedBlueprint == null)
            {
                xp = xp * 1.25f;
                player.SendMessage("You receive an XP bonus for crafting this item for the first time.");

                pcCraftedBlueprint = new PCCraftedBlueprint
                {
                    CraftBlueprintID = blueprint.ID,
                    DateFirstCrafted = DateTime.UtcNow,
                    PlayerID         = player.GlobalID
                };

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

            _skill.GiveSkillXP(player, blueprint.SkillID, (int)xp);
            _craft.ClearPlayerCraftingData(player, true);
        }