Exemplo n.º 1
0
        public void KillEntity(int id)
        {
            var msg = Networking.CreateMessage();

            msg.Write((byte)GameScreen.ServerHeaders.KILL_ENTITY);

            msg.Write(id);
            Networking.SendMessage(msg, NetDeliveryMethod.ReliableOrdered, 1);

            NPCs.RemoveAt(id);
        }
Exemplo n.º 2
0
        public void StartEvent()
        {
            //Random rand = new Random(Guid.NewGuid().GetHashCode());
            int count = NPCs.Count;

            if (count > 0)
            {
                Console.Write("You see ");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write(count > 1 ? count.ToString() + " " + NPCs[0].name + "s" : "a " + NPCs[0].name);
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine(".");

                if (rand.Next(100) < 90) // 10% chance to get spooted
                {                        // hidden
                    heroStatus = Statuses.Hidden_Far;
                }
                else
                {                        // spotted
                    heroStatus = Statuses.Spotted;
                }
            }
            else            // no NPC's
            {
                heroStatus = Statuses.Clear;
            }

            while (true)
            {
                string replyString = AskPlayerAQuestion();
                if (replyString == "" || replyString == null)
                {
                    ThrowUnexpectedMessage();
                    continue;
                }
                char reply = replyString[0];
                switch (reply)
                {
                case 's':
                    if (heroStatus == Statuses.Hidden_Far)
                    {
                        if (hero.SneakCheck(1))                   // trying to sneak closer
                        {
                            heroStatus = Statuses.Hidden_Close;
                        }
                        else
                        {
                            heroStatus = Statuses.Spotted;
                        }
                    }
                    else if (heroStatus == Statuses.Hidden_Close)
                    {
                        if (hero.SneakCheck(1.5))                 // trying to perform sneak attack
                        {
                            Console.Write("You've ");
                            Console.ForegroundColor = ConsoleColor.Gray;
                            Console.Write("killed ");
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Write(NPCs[0].name);
                            Console.ForegroundColor = ConsoleColor.White;

                            NPCs.RemoveAt(0);

                            if (NPCs.Count > 0)
                            {
                                if (hero.SneakCheck(1))                         // check stealth after attack (to hide body)
                                {
                                    Console.WriteLine(" and wasn't spooted.");
                                }
                                else
                                {                                               // spotted after attack
                                    Console.WriteLine(" but was spotted. Prepare to fight!");
                                    heroStatus = Statuses.Spotted;
                                }
                            }
                            else
                            {                                                               // check NPC count
                                Console.WriteLine(" and it was the last of them.");
                                heroStatus = Statuses.Clear;
                                break;
                            }
                        }
                        else
                        {                                                   // spotted before attack
                            Console.Write("You've tried to attack ");
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Write(NPCs[0].name);
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.WriteLine(" but he spotted you before. Prepare to fight!");

                            heroStatus = Statuses.Spotted;
                        }
                    }
                    else
                    {
                        ThrowUnexpectedMessage();
                    }
                    break;

                case 'a':
                    if (heroStatus == Statuses.Hidden_Far || heroStatus == Statuses.Spotted)
                    {
                        Console.WriteLine("You draw your weapon and take a battle stance.");            // proceed to fighting
                        heroStatus = Statuses.Fighting;
                    }
                    else if (heroStatus == Statuses.Fighting)
                    {
                        int targetIndex = 0;
                        NPC target;

                        if (NPCs.Count > 1)
                        {
                            Console.WriteLine("Choose target to attack: ");
                            for (int i = 0; i < NPCs.Count; i++)
                            {
                                Console.WriteLine((i + 1).ToString() + ". " + NPCs[i].name + (NPCs[i].HP < NPCs[i].maxHP ? " (wounded)" : ""));
                            }

                            while (true)
                            {                                                                   // trying to get index from player
                                try
                                {
                                    targetIndex = Convert.ToInt32(Console.ReadLine()) - 1;      // possible exception
                                    target      = NPCs[targetIndex];                            // possible exception
                                    break;
                                }
                                catch
                                {
                                    ThrowUnexpectedMessage();
                                }
                            }
                        }
                        else
                        {
                            target = NPCs[targetIndex];
                        }
                        // attacking NPC
                        int damage = hero.Attack(ref target);
                        Console.Write("You attacked ");
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write(target.name);
                        Console.ForegroundColor = ConsoleColor.White;
                        if (damage > 0)
                        {
                            Console.Write(" and did ");
                            Console.ForegroundColor = ConsoleColor.Magenta;
                            Console.Write(damage.ToString());
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.WriteLine(" damage.");
                        }
                        else
                        {
                            Console.Write(" but ");
                            Console.ForegroundColor = ConsoleColor.Magenta;
                            Console.Write("missed");
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.WriteLine(".");
                        }

                        if (target.HP <= 0)
                        {                                       // HP check
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Write(target.name);
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.WriteLine(" is dead.");

                            NPCs.RemoveAt(targetIndex);
                            if (NPCs.Count <= 0)                    // clear check
                            {
                                Console.WriteLine("Looks like there is no one left standing except you.");
                                heroStatus = Statuses.Clear;
                                break;                              // if clear it breaks here
                            }
                        }
                        heroStatus = Statuses.Fighting;

                        AttackHero();      // attacking hero
                    }
                    break;

                case 'r':                           // trying to run away
                    if (heroStatus == Statuses.Hidden_Close || heroStatus == Statuses.Hidden_Far)
                    {                               // if not spotted chances to run are 100%
                        Console.WriteLine("You ran away.");
                        heroStatus = Statuses.Away;
                    }
                    else if (heroStatus == Statuses.Spotted || heroStatus == Statuses.Fighting)
                    {
                        if (rand.Next(2) == 1)
                        {                                               // if spotted chances to run are 50%
                            Console.WriteLine("You ran away.");
                            heroStatus = Statuses.Away;
                        }
                        else
                        {
                            Console.WriteLine("You wasn't able to run away.");
                            heroStatus = Statuses.Fighting;
                            AttackHero();             // attacking hero
                        }
                    }
                    else
                    {
                        ThrowUnexpectedMessage();
                    }
                    break;

                case 'g':                                   // go before looting
                    if (heroStatus == Statuses.Clear)
                    {
                        Console.WriteLine("You leave this place.");
                        heroStatus = Statuses.Away;
                    }
                    else
                    {
                        ThrowUnexpectedMessage();
                    }
                    break;

                case 'l':
                    if (heroStatus == Statuses.Clear)           // start looting
                    {
                        GenerateLoot();

                        if (Loot.Count <= 0)
                        {
                            Console.WriteLine("You have found nothing and decide to leave this place.");
                            heroStatus = Statuses.Away;
                            break;
                        }

                        int  itemIndex;
                        Item item;
                        while (true)
                        {                                                                   // trying to get index from player
                            Console.WriteLine("You've found these items:");
                            for (int i = 0; i < Loot.Count; i++)
                            {
                                Console.WriteLine((i + 1).ToString() + ". " + Loot[i].ToString());
                            }
                            Console.Write("Input index to take item or (leave): ");

                            string lootReply = Console.ReadLine().ToLower();

                            if (lootReply == "leave" || lootReply == "l")
                            {
                                Console.WriteLine("You leave this place.");
                                heroStatus = Statuses.Away;
                                break;
                            }
                            try
                            {
                                itemIndex = Convert.ToInt32(lootReply) - 1;      // possible exception
                                item      = Loot[itemIndex];                     // possible exception
                                hero.AddItem(item);
                                Loot.RemoveAt(itemIndex);
                            }
                            catch
                            {
                                ThrowUnexpectedMessage();
                                break;
                            }

                            if (Loot.Count <= 0)
                            {
                                Console.WriteLine("There is nothing more. You leave this place.");
                                heroStatus = Statuses.Away;
                                break;
                            }
                        }
                    }
                    else
                    {
                        ThrowUnexpectedMessage();
                    }
                    break;

                case 'i':
                    hero.ManageInventory();
                    break;

                case 'c':
                    hero.ShowStats();
                    break;

                default:
                    ThrowUnexpectedMessage();
                    break;
                }
                if (heroStatus == Statuses.Dead || heroStatus == Statuses.Away)
                {
                    break;
                }
            }
        }