Ejemplo n.º 1
0
 static private void CancelEvent(WorldEvent worldEvent)
 {
     if (worldEvent.EffectID[0])
     {
         UnApplyItemModifier(worldEvent);
     }
     if (worldEvent.EffectID[1])
     {
         UnApplyInventory(worldEvent);
     }
     activeEvents.Remove(worldEvent);
 }
Ejemplo n.º 2
0
        static public void EventFire(int id, string[] target, Random rnd)
        {
            WorldEvent newWorldEvent = GenerateEvent(id, target, rnd);

            if (newWorldEvent.EffectID[0])
            {
                ApplyItemModifier(newWorldEvent);
            }

            if (newWorldEvent.EffectID[1])
            {
                ApplyInventory(newWorldEvent);
            }
            activeEvents.Add(newWorldEvent);
        }
Ejemplo n.º 3
0
        static private WorldEvent GenerateEvent(int id, string[] target, Random rnd)
        {
            WorldEvent newWorldEvent;

            newWorldEvent = new WorldEvent(eventNameList[id], eventDesList[id], id, eventCounter, target, effectIDList[id], effectValList[id], durationList[id]);
            eventCounter++;
            int mod = rnd.Next(0, durationModList[id] + 1);

            if (rnd.Next(0, 2) == 1)
            {
                newWorldEvent.DaysLeft += mod;
            }
            else
            {
                newWorldEvent.DaysLeft -= mod;
            }
            GlossaryManager.CheckWorldEvents(newWorldEvent.EventID);
            return(newWorldEvent);
        }
Ejemplo n.º 4
0
        static private void ApplyInventory(WorldEvent newWorldEvent)
        {
            foreach (InventoryTemplate newInv in inventoryList)
            {
                if (newInv.ID == newWorldEvent.EffectVal[1]) //finds the correct inventoryTemplate
                {
                    foreach (string cityTarget in newWorldEvent.Target)
                    {
                        foreach (City tempCity in WorldMapMenu.Cities)
                        {
                            if (cityTarget == tempCity.Name)                                        //locates the cities that are targeted by the event
                            {
                                newWorldEvent.OldTemplateInv = new Inventory(tempCity.TemplateInv); //saves the city's old inventory
                                Inventory newTemplateInv = new Inventory(tempCity.TemplateInv);
                                for (int i = 0; i < newInv.AmountNegativeOrPositive.Count; i++)
                                {
                                    Item fixedItem = newInv.Items[i];
                                    int  counter   = 0;

                                    for (int j = 0; j < tempCity.TemplateInv.ItemList.Count; j++)
                                    {
                                        if (fixedItem.ID == tempCity.TemplateInv.ItemList[j].ID)
                                        {
                                            counter += tempCity.TemplateInv.ItemList[j].Amount; //räknar hur många som finns av det itemet i staden (eftersom det ändras procentuellt)
                                        }
                                    }

                                    float temp = (fixedItem.Amount / 100f) * counter; //konverterar procenten och hur mycket som fanns till ett faktiskt värde

                                    fixedItem.Amount = (int)(temp + 0.5f);

                                    ApplyFixedItem(fixedItem, newTemplateInv, newInv, i);
                                }
                                tempCity.TemplateInv = new Inventory(newTemplateInv);
                                tempCity.CheckDate();
                                tempCity.InvReset();
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
 static private void UnApplyInventory(WorldEvent worldEvent)
 {
     foreach (InventoryTemplate newInv in inventoryList)
     {
         if (newInv.ID == worldEvent.EffectVal[1])
         {
             foreach (string cityTarget in worldEvent.Target)
             {
                 foreach (City tempCity in WorldMapMenu.Cities)
                 {
                     if (cityTarget == tempCity.Name)
                     {
                         tempCity.TemplateInv = worldEvent.OldTemplateInv;
                         tempCity.CheckDate();
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 6
0
 static private void ApplyItemModifier(WorldEvent newWorldEvent)
 {
     foreach (ItemModifierTemplate newMod in itemModifierList)
     {
         if (newMod.ID == newWorldEvent.EffectVal[0])
         {
             foreach (string cityTarget in newWorldEvent.Target)
             {
                 foreach (City tempCity in WorldMapMenu.Cities)
                 {
                     if (cityTarget == tempCity.Name)
                     {
                         for (int i = 0; i < newMod.ItemCategories.Count; i++)
                         {
                             ModifierManager.AddModifier(cityTarget, newMod.ItemCategories[i], newMod.ItemModifiers[i]);
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 7
0
 static private void UnApplyItemModifier(WorldEvent worldEvent)
 {
     foreach (ItemModifierTemplate newMod in itemModifierList)
     {
         if (newMod.ID == worldEvent.EffectVal[0])
         {
             foreach (string cityTarget in worldEvent.Target)
             {
                 foreach (City tempCity in WorldMapMenu.Cities)
                 {
                     if (cityTarget == tempCity.Name)
                     {
                         for (int i = 0; i < newMod.ItemCategories.Count; i++)
                         {
                             float tempMod = -(newMod.ItemModifiers[i] * 2);
                             ModifierManager.SetModifier(cityTarget, newMod.ItemCategories[i], tempMod);
                         }
                     }
                 }
             }
         }
     }
 }