Ejemplo n.º 1
0
        public override WorldEvent GenerateObject(Hero hero, IFactory <WorldEvent> factory = null)
        {
            EventRarity rarity     = EventRarity.Common;
            WorldEvent  worldEvent = null;

            while (worldEvent == null)
            {
                rarity     = GenerateRarity();
                worldEvent = GenerateEvent(rarity);
            }

            if (worldEvent.UniquePerSession || worldEvent.UniquePerHero)
            {
                // Remove it from our list
                Events[rarity].Remove(worldEvent);

                // Have we already done this event on this hero?
                if (worldEvent.UniquePerHero)
                {
                    // Find a different event
                    if (hero.UniqueEventsSeen.Contains(worldEvent.Name))
                    {
                        return(GenerateObject(hero));
                    }
                    // Remember this event
                    else
                    {
                        hero.UniqueEventsSeen.Add(worldEvent.Name);
                    }
                }
            }

            worldEvent.Hero = hero;
            return(worldEvent);
        }
Ejemplo n.º 2
0
    public EventData GetEvent(EventType type = EventType.Random, EventRarity rarity = EventRarity.Random, EventGoodness goodness = EventGoodness.Random, bool force = true)
    {
        List <EventData> compatibleEvents = new List <EventData>(_events);

        compatibleEvents.RemoveAll(e => e.Type == EventType.Special);

        if (type != EventType.Random)
        {
            compatibleEvents.RemoveAll(e => e.Type != type);
        }

        if (rarity != EventRarity.Random)
        {
            compatibleEvents.RemoveAll(e => e.Rarity != rarity);
        }
        else
        {
            int rndRarity = _rnd.Next(9);
            if (rndRarity <= 3)
            {
                compatibleEvents.RemoveAll(e => e.Rarity != EventRarity.Often);
            }
            else if (rndRarity <= 6)
            {
                compatibleEvents.RemoveAll(e => e.Rarity != EventRarity.Regular);
            }
            else
            {
                compatibleEvents.RemoveAll(e => e.Rarity != EventRarity.Rare);
            }
        }

        if (goodness != EventGoodness.Random)
        {
            compatibleEvents.RemoveAll(e => e.Goodness != goodness);
        }
        else
        {
            compatibleEvents.RemoveAll(e => e.Goodness != GetGoodness());
        }

        if (compatibleEvents.Count == 0)
        {
            if (force)
            {
                compatibleEvents = _events;
            }
            else
            {
                return(null);
            }
        }

        int index = _rnd.Next(compatibleEvents.Count);

        return(compatibleEvents[index]);
    }
Ejemplo n.º 3
0
        private WorldEvent GenerateEvent(EventRarity rarity)
        {
            int index = random.Next(0, Events[rarity].Count);

            WorldEvent worldEvent = null;

            if (Events[rarity].Count != 0)
            {
                worldEvent = Events[rarity][index];
            }

            return(worldEvent);
        }
Ejemplo n.º 4
0
        public WorldEventTable()
        {
            random = new Random();

            Weights = new Dictionary <EventRarity, double>();
            Weights[EventRarity.Common]    = 0.67;
            Weights[EventRarity.Uncommon]  = 0.20;
            Weights[EventRarity.Rare]      = 0.11;
            Weights[EventRarity.Legendary] = 0.02;

            Events = new Dictionary <EventRarity, List <WorldEvent> >();
            for (EventRarity rarity = EventRarity.Common; rarity <= EventRarity.Legendary; ++rarity)
            {
                Events[rarity] = new List <WorldEvent>();
            }
        }