Example #1
0
        static void Main(string[] args)
        {
            bool coffeeMachineIsRunning = false;
            bool pottedPlantIsRunning   = false;
            bool engineIsRunning        = false;
            bool isRunning = true;

            while (isRunning)
            {
                Console.WriteLine("To enter the coffee machine, type cm \n" +
                                  "To enter the potted plant, type pp \n" +
                                  "To enter the engine, type e \n" +
                                  "Or type exit to quit");
                string input = Console.ReadLine();
                switch (input.ToLower())
                {
                case "cm":
                    coffeeMachineIsRunning = true;
                    break;

                case "pp":
                    pottedPlantIsRunning = true;
                    break;

                case "e":
                    engineIsRunning = true;
                    break;

                case "exit":
                    isRunning = false;
                    break;

                default:
                    Console.WriteLine("I didn't understand, please try again.");
                    break;
                }


                while (pottedPlantIsRunning)
                {
                    PottedPlant pottedPlant = new PottedPlant();
                    pottedPlant.numberOfLeaves = 127;
                    Console.Clear();
                    bool isPottedPlantRunning = true;
                    while (isPottedPlantRunning)
                    {
                        Console.WriteLine("What do you want to do? \n" +
                                          "If you want to look at the plant, write look \n" +
                                          "If you want to count the number of leaves, type count \n" +
                                          "If you want to see if the plant is real, type check \n" +
                                          "If you want to see if the POTTED plant is in a pot, type pot\n" +
                                          "If you want to water the plant, type water");
                        input = Console.ReadLine();
                        switch (input.ToLower())
                        {
                        case "look":
                            pottedPlant.Lookatplant();;
                            break;

                        case "count":
                            pottedPlant.CountNumberOfLeaves();
                            break;

                        case "check":
                            pottedPlant.IsReal();
                            break;

                        case "pot":
                            pottedPlant.IsInPot();
                            break;

                        case "water":
                            pottedPlant.IsPlantWatered();
                            break;

                        default:
                            Console.WriteLine("I'm sorry I don't understand");
                            break;
                        }
                        Console.Clear();
                    }
                }

                while (engineIsRunning)
                {
                    Console.Clear();
                    Engine engine = new Engine();
                    engine.brand          = "Volvo";
                    engine.cylinders      = 6;
                    engine.engineCapacity = 2.4;
                    bool isEngineRunning = true;
                    while (isEngineRunning)
                    {
                        Console.WriteLine("What do you want to do? \n" +
                                          "If you want to start the engine write start \n" +
                                          "If you want to move the engine write move \n" +
                                          "If you want to see if the engine needs cleaning write clean \n" +
                                          "If you want to fill the engine with fuel write fuel \n" +
                                          "If you want information about the engine write info");
                        input = Console.ReadLine();

                        switch (input.ToLower())
                        {
                        case "start":
                            engine.EngineStart(engine);
                            break;

                        case "move":
                            engine.Movable();
                            break;

                        case "clean":
                            engine.NeedCleaning();
                            break;

                        case "fuel":
                            engine.FillWithFuel(engine);
                            break;

                        case "info":
                            engine.InformationAboutEngine();
                            break;

                        default:
                            Console.WriteLine("I'm sorry I don't understand");
                            break;
                        }
                        Console.Clear();
                    }
                }



                while (coffeeMachineIsRunning)
                {
                    Coffemachine coffemachine = new Coffemachine();

                    Console.WriteLine("Please set the cost of coffee");
                    input = Console.ReadLine();
                    coffemachine.PriceOfCoffee(input);
                    bool isRunningCM = true;
                    while (isRunningCM)
                    {
                        Console.Clear();
                        Console.WriteLine("Do you want a cup of coffee? Then write coffee \n" +
                                          "Do you want to know how much coffee is currently in the machine? Then write status \n" +
                                          "Do you want to fill up the machine? Then write fill \n" +
                                          "");
                        input = Console.ReadLine();

                        switch (input.ToLower())
                        {
                        case "coffee":
                            coffemachine = coffemachine.ButtonPress(coffemachine);
                            break;

                        case "status":
                            coffemachine.CurrentAmountOfCoffee(coffemachine);
                            break;

                        case "fill":
                            coffemachine = coffemachine.FillMachine(coffemachine);
                            break;

                        case "hit":
                            coffemachine.Hit();
                            break;

                        default:
                            Console.WriteLine("I'm sorry I didn't understand that. Please try again.");
                            break;
                        }
                        Console.Clear();
                    }
                }
            }
        }
        private void GiveMagicItems()
        {
            ArrayList toGive = new ArrayList();

            LogHelper Logger = new LogHelper("HarrowerLoot.log", false);


            ArrayList allNonExpiredPMDamageEntries = new ArrayList();

            //New Looting method (Pix: 4/8/06)
            for (int i = 0; i < DamageEntries.Count; i++)
            {
                DamageEntry de = DamageEntries[i] as DamageEntry;
                if (de != null)
                {
                    Logger.Log(LogType.Text, string.Format("DE[{0}]: {1} ({2})", i, de.Damager, de.Damager != null ? de.Damager.Name : ""));
                    if (de.HasExpired)
                    {
                        Logger.Log(LogType.Text, string.Format("DE[{0}]: Expired", i));
                    }
                    else
                    {
                        if (de.Damager != null && !de.Damager.Deleted)
                        {
                            if (de.Damager is BaseCreature)
                            {
                                Logger.Log(LogType.Text, string.Format("DE[{0}]: BaseCreature", i));
                                BaseCreature bc = (BaseCreature)de.Damager;
                                if (bc.ControlMaster != null && !bc.ControlMaster.Deleted)
                                {
                                    //de.Damager = bc.ControlMaster;
                                    DamageEntry cmde = new DamageEntry(bc.ControlMaster);
                                    cmde.DamageGiven = de.DamageGiven;
                                    de = cmde;
                                    Logger.Log(LogType.Text, string.Format("DE[{0}]: New Damager: {1}", i, de.Damager.Name));
                                }
                            }

                            if (de.Damager is PlayerMobile)
                            {
                                Logger.Log(LogType.Text, string.Format("DE[{0}]: PlayerMobile", i));

                                if (de.Damager.Alive)
                                {
                                    Logger.Log(LogType.Text, string.Format("DE[{0}]: PM Alive", i));

                                    bool bFound = false;
                                    for (int j = 0; j < allNonExpiredPMDamageEntries.Count; j++)
                                    {
                                        DamageEntry de2 = (DamageEntry)allNonExpiredPMDamageEntries[j];
                                        if (de2.Damager == de.Damager)
                                        {
                                            Logger.Log(LogType.Text, string.Format("DE[{0}]: PM Found, adding damage", i));

                                            de2.DamageGiven += de.DamageGiven;
                                            bFound           = true;
                                            break;
                                        }
                                    }

                                    if (!bFound)
                                    {
                                        Logger.Log(LogType.Text, string.Format("DE[{0}]: PM not found, adding", i));
                                        allNonExpiredPMDamageEntries.Add(de);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //Remove any PMs that are over 100 tiles away
            ArrayList toRemove = new ArrayList();

            for (int i = 0; i < allNonExpiredPMDamageEntries.Count; i++)
            {
                DamageEntry de = (DamageEntry)allNonExpiredPMDamageEntries[i];
                if (de.Damager.GetDistanceToSqrt(this.Location) > 100)
                {
                    Logger.Log(LogType.Text, string.Format("Removing {0} for being too far away at death", de.Damager.Name));
                    toRemove.Add(allNonExpiredPMDamageEntries[i]);
                }
            }
            for (int i = 0; i < toRemove.Count; i++)
            {
                allNonExpiredPMDamageEntries.Remove(toRemove[i]);
            }

            int topDamage = 0;
            int minDamage = 0;

            for (int i = 0; i < allNonExpiredPMDamageEntries.Count; i++)
            {
                DamageEntry de = (DamageEntry)allNonExpiredPMDamageEntries[i];
                if (de.DamageGiven > topDamage)
                {
                    topDamage = de.DamageGiven;
                }

                Logger.Log(LogType.Text, string.Format("Non-Expired[{0}]: {1} (damage: {2})", i, de.Damager.Name, de.DamageGiven));
            }

            //Now filter on 'enough' damage
            if (HitsMax >= 3000)
            {
                minDamage = topDamage / 16;
            }
            else if (HitsMax >= 1000)
            {
                minDamage = topDamage / 8;
            }
            else if (HitsMax >= 200)
            {
                minDamage = topDamage / 4;
            }
            else
            {
                minDamage = topDamage / 2;
            }

            Logger.Log(LogType.Text, string.Format("HitsMax: {0}, TopDamage: {1}, MinDamage: {2}", HitsMax, topDamage, minDamage));


            for (int i = 0; i < allNonExpiredPMDamageEntries.Count; i++)
            {
                DamageEntry de = (DamageEntry)allNonExpiredPMDamageEntries[i];
                if (de.DamageGiven >= minDamage)
                {
                    toGive.Add(de.Damager);
                }
            }


            if (toGive.Count == 0)
            {
                return;
            }

            // Randomize
            for (int i = 0; i < toGive.Count; ++i)
            {
                int    rand = Utility.Random(toGive.Count);
                object hold = toGive[i];
                toGive[i]    = toGive[rand];
                toGive[rand] = hold;
            }

            Logger.Log(LogType.Text, "");             // new line
            Logger.Log(LogType.Text, "Randomized list of players:");
            for (int i = 0; i < toGive.Count; ++i)
            {
                Mobile mob = toGive[i] as Mobile;
                Logger.Log(LogType.Mobile, mob, "alive:" + mob.Alive.ToString());
            }

            Logger.Log(LogType.Text, "");             // new line
            Logger.Log(LogType.Text, "Begin loot distribution: Who/What:");

            // Loop goes until we've generated MaxGifts items.
            for (int i = 0; i < MaxGifts; ++i)
            {
                Item   reward = null;
                Mobile m      = (Mobile)toGive[i % toGive.Count];

                switch (Utility.Random(10))
                {
                case 0:                         // Power/Vanq Weapon
                case 1:
                case 2:                         // 3 in 10 chance
                {                               // 33% chance at best
                    reward = CreateWeapon((0.32 >= Utility.RandomDouble()) ? 5 : 4);
                    break;
                }

                case 3:                         // Fort/Invul Armor
                case 4:
                case 5:                         // 3 in 10 chance
                {                               // 33% chance at best
                    reward = CreateArmor((0.32 >= Utility.RandomDouble()) ? 5 : 4);
                    break;
                }

                case 6:                                 // hair/beard dye
                {                                       // 1 in 10 chance
                    if (Utility.RandomBool())
                    {
                        reward = new SpecialHairDye();
                    }
                    else
                    {
                        reward = new SpecialBeardDye();
                    }
                    break;
                }

                case 7:                                 // special cloth
                {                                       // 1 in 10 chance
                    reward = new UncutCloth(50);
                    if (Utility.RandomBool())
                    {
                        // best ore hues (vet rewards) + really dark 'evil cloth'
                        reward.Hue = Utility.RandomList(2213, 2219, 2207, 2425, 1109);
                    }
                    else
                    {
                        reward.Hue = 0x01;                                              // black cloth
                    }
                    break;
                }

                case 8:                                 // potted plant
                {                                       // 1 in 10 chance
                    switch (Utility.Random(11))
                    {
                    default:                                                    // should never happen
                    case 0: reward = new PottedCactus(); break;

                    case 1: reward = new PottedCactus1(); break;

                    case 2: reward = new PottedCactus2(); break;

                    case 3: reward = new PottedCactus3(); break;

                    case 4: reward = new PottedCactus4(); break;

                    case 5: reward = new PottedCactus5(); break;

                    case 6: reward = new PottedPlant(); break;

                    case 7: reward = new PottedPlant1(); break;

                    case 8: reward = new PottedPlant2(); break;

                    case 9: reward = new PottedTree(); break;

                    case 10: reward = new PottedTree1(); break;
                    }
                    break;
                }

                default:                                // Should never happen
                /* fall through*/

                case 9:                                 // Magic Item Drop
                {                                       // 1 in 10 chance
                    reward = Loot.RandomClothingOrJewelry();
                    if (reward != null)
                    {
                        int minLevel = 3;
                        int maxLevel = 3;
                        if (reward is BaseClothing)
                        {
                            ((BaseClothing)reward).SetRandomMagicEffect(minLevel, maxLevel);
                        }
                        else if (reward is BaseJewel)
                        {
                            ((BaseJewel)reward).SetRandomMagicEffect(minLevel, maxLevel);
                        }
                    }
                    break;
                }
                }

                if (reward != null)
                {
                    // Drop the new weapon into their backpack and send them a message.
                    m.SendMessage("You have received a special item!");
                    m.AddToBackpack(reward);

                    Logger.Log(LogType.Mobile, m, "alive:" + m.Alive.ToString());
                    Logger.Log(LogType.Item, reward, string.Format("Hue:{0}:Rare:{1}",
                                                                   reward.Hue,
                                                                   (reward is BaseWeapon || reward is BaseArmor || reward is BaseClothing || reward is BaseJewel) ? "False" : "True"));
                }
            }

            // done logging
            Logger.Finish();
        }