예제 #1
0
        public static void AdjustPrice(CLRScriptBase script, uint target, int adjustBy)
        {
            if (script.GetObjectType(target) != OBJECT_TYPE_ITEM)
                return;

            if (adjustBy == 0)
                return;

            string itemKey = PriceChangeVarName + target.ToString();
            if (script.GetItemStackSize(target) > 1)
            {
                stackSizes.Add(itemKey, script.GetItemStackSize(target));
                script.SetItemStackSize(target, 1, FALSE);
            }
            script.StoreCampaignObject(ItemChangeDBName, itemKey, target, script.OBJECT_SELF);
            if (ALFA.Shared.Modules.InfoStore.ModifiedGff.Keys.Contains(itemKey))
            {
                int currentModifyCost = 0;
                currentModifyCost = ALFA.Shared.Modules.InfoStore.ModifiedGff[itemKey].TopLevelStruct["ModifyCost"].ValueInt + adjustBy;
                ALFA.Shared.Modules.InfoStore.ModifiedGff[itemKey].TopLevelStruct["ModifyCost"].ValueInt = currentModifyCost;
                
                script.DestroyObject(target, 0.0f, FALSE);
                script.DelayCommand(0.1f, delegate() 
                { 
                    uint newObject = script.RetrieveCampaignObject(ItemChangeDBName, itemKey, script.GetLocation(script.OBJECT_SELF), script.OBJECT_SELF, script.OBJECT_SELF);
                    if (stackSizes.Keys.Contains(itemKey))
                    {
                        script.SetItemStackSize(newObject, stackSizes[itemKey], FALSE);
                        stackSizes.Remove(itemKey);
                    }
                    if (script.GetObjectType(script.OBJECT_SELF) != OBJECT_TYPE_PLACEABLE)
                    {
                        script.CopyItem(newObject, script.OBJECT_SELF, TRUE);
                        script.DestroyObject(newObject, 0.0f, FALSE);
                    }
                });
            }
        }
예제 #2
0
        public static void CalculatePrice(CLRScriptBase script, uint target)
        {
            #region Reject to Price Objects Which Can't or Shouldn't be Priced
            if (script.GetObjectType(target) != OBJECT_TYPE_ITEM)
            {
                return;
            }

            int itemType = script.GetBaseItemType(target);
            if (GetIsOOCItem(itemType))
            {
                return;
            }
            #endregion

            #region Find out What the Item Should be Worth
            int targetValue = 0;
            if (GetIsWeapon(itemType) || GetIsAmmunition(itemType))
            {
                targetValue = GetWeaponPrice(script, target);
            }
            else if (GetIsArmor(itemType))
            {
                targetValue = GetArmorPrice(script, target);
            }
            else
            {
                targetValue = GetWonderousPrice(script, target);
            }
            #endregion

            #region Early Return for Illegal and Custom-Scripted Items
            if (targetValue == -1)
            {
                // We can't price this item, because it's illegal.
                script.SetFirstName(target, "(Illegal) " + script.GetName(target));
                return;
            }
            else if (targetValue == -2)
            {
                return;
            }
            #endregion

            #region Determine if the Item Requires Adjustment, and Adjust if Necessary
            bool isPlot = false;
            bool isUnidentified = false;
            if (script.GetLocalInt(target, localVarName) == pricingVersion)
            {
                // We've already used this logic to price this item. We have nothing to add.
                return;
            }
            if (script.GetPlotFlag(target) == TRUE)
            {
                script.SetPlotFlag(target, FALSE);
                isPlot = true;
            }
            if (script.GetIdentified(target) == FALSE)
            {
                script.SetIdentified(target, TRUE);
                isUnidentified = true;
            }
            int currentValue = script.GetGoldPieceValue(target);
            if (script.GetItemStackSize(target) > 1)
            {
                currentValue /= script.GetItemStackSize(target);
            }
            if (currentValue != targetValue)
            {
                script.StoreCampaignObject(ItemChangeDBName, PriceChangeVarName, target, script.OBJECT_SELF);
                if (ALFA.Shared.Modules.InfoStore.ModifiedGff.Keys.Contains(PriceChangeVarName))
                {
                    if (ALFA.Shared.Modules.InfoStore.ModifiedGff[PriceChangeVarName].TopLevelStruct["ModifyCost"].ValueInt == 0 ||
                        targetValue > currentValue ||
                        script.GetLocalInt(target, localVarName) != 0)
                    {
                        // We only want to adjust the price if either a) no effort to control the item's price has been made or
                        // b) the item is actually less valuable than the current price reads. Artificial inflations of price are
                        // legal in ALFA.

                        // Also, if this item was priced automatically, we want to be able to correct it.
                        script.SetLocalInt(target, localVarName, pricingVersion);
                        AdjustPrice(script, target, targetValue - currentValue);
                    }
                }
            }
            if (isPlot)
            {
                script.SetPlotFlag(target, TRUE);
            }
            if (isUnidentified)
            {
                script.SetIdentified(target, FALSE);
            }
            #endregion
        }