コード例 #1
0
 public void Drain()
 {
     currentCharge -= chargeDecayRate;
     User.User temp = MySockets.Server.GetAUser(this.Owner);
     if ((Math.Round(currentCharge / maxCharge, 2) * 100) == chargeLowWarning)
     {
         //TODO: these message should be grabbed from the DB and should reflect the type of light it is
         if (temp != null)
         {
             temp.MessageHandler("The light from your " + this.Name.ToLower() + " flickers.");
         }
         chargeLowWarning = chargeLowWarning / 2;
     }
     if (Math.Round(currentCharge, 2) <= 0)
     {
         currentCharge    = 0.0;
         chargeLowWarning = 10;
         isLit            = false;
         //TODO: these message should be grabbed from the DB and should reflect the type of light it is
         if (temp != null)
         {
             temp.MessageHandler("The light from your " + this.Name.ToLower() + " goes out.");
         }
     }
     OnDrained(new ItemEventArgs(ItemEvent.DRAIN, this.Id));
     temp.Player.Inventory.GetInventoryAsItemList(); //this will force an update on the inventory items
     temp.Player.Equipment.GetEquipment();           //this will force an update on the equipment
     this.Save();
 }
コード例 #2
0
ファイル: Character.cs プロジェクト: vadian/Novus
        public void RewardXP(string id, long xpGained)
        {
            MongoUtils.MongoData.ConnectToDatabase();
            MongoDatabase   db   = MongoUtils.MongoData.GetDatabase("Characters");
            MongoCollection npcs = db.GetCollection("NPCCharacters");
            BsonDocument    npc  = npcs.FindOneAs <BsonDocument>(Query.EQ("_id", ObjectId.Parse(id)));

            User.User temp = MySockets.Server.GetAUser(ID);
            if (string.IsNullOrEmpty(temp.GroupName))
            {
                temp.MessageHandler(string.Format("You gain {0:0.##} XP from {1}", xpGained, npc["FirstName"].AsString.CamelCaseWord()));
                Experience += xpGained;
            }
            else
            {
                //we want to know how much XP the NPC would give out and cut it by half if player is in a group
                Groups.Groups.GetInstance().RewardXP((long)(npc["XP"].AsInt64 * 0.5), temp.GroupName);
            }
            if (IsLevelUp && !Leveled)                                      //we don't want the player to just farm a ton of points and continue to level up, we want them to type the command before we show this message again
            {
                temp.MessageHandler("Congratulations! You've leveled up!"); //let's let them know they can level up it's up to them when they actually do level up
                Character tempChar = temp.Player as Character;
                Leveled = true;
                tempChar.NextLevelExperience += (long)(tempChar.NextLevelExperience * 1.25);
                IncreasePoints();
                //increase all the attributes to max, small perk of leveling up.  Maybe a global setting?
                foreach (KeyValuePair <string, Attribute> attrib in temp.Player.GetAttributes())
                {
                    attrib.Value.Value = attrib.Value.Max;
                }
            }
        }
コード例 #3
0
ファイル: Group.cs プロジェクト: vadian/Novus
 public void RewardXP(long xpAmount)
 {
     foreach (string playerID in PlayerList)
     {
         User.User user = MySockets.Server.GetAUser(playerID);
         user.MessageHandler(string.Format("You gain {0:0.##} XP", xpAmount));
         user.Player.Experience += xpAmount;
     }
 }
コード例 #4
0
ファイル: Group.cs プロジェクト: vadian/Novus
 private void MasterLooterLoots(User.User looter, List <string> commands, Character.Iactor npc)
 {
     if (string.Equals(looter.UserID, MasterLooter))
     {
         ((Character.NPC)npc).Loot(looter, commands, true);
     }
     else
     {
         looter.MessageHandler("Only the master looter can loot corpses killed by the group.");
     }
 }
コード例 #5
0
        //static methods that don't apply to creating a room object
        public static void ApplyRoomModifiers(int tick)
        {
            MongoCollection roomCollection     = MongoUtils.MongoData.GetCollection("World", "Rooms");
            MongoCollection modifierCollection = MongoUtils.MongoData.GetCollection("World", "RoomModifiers");
            MongoCursor     roomsFound         = roomCollection.FindAs <BsonDocument>(Query.Exists("Modifiers"));

            //allright this isn't as bad as it seems this actually executed pretty fast and it's running on a separate thread anyways since it's
            //coming off a timer event
            Room room = null;

            foreach (BsonDocument doc in roomsFound)
            {
                room = Room.GetRoom(doc["_id"].AsString);

                BsonArray modArray = doc["Modifiers"].AsBsonArray;

                foreach (BsonDocument mods in modArray.Where(m => m.AsBsonDocument.Count() > 0))
                {
                    BsonDocument modFound = modifierCollection.FindOneAs <BsonDocument>(Query.EQ("_id", mods["id"]));

                    if (modFound["Timer"].AsInt32 > 0 && tick % modFound["Timer"].AsInt32 == 0)   //we only want to go through the rooms where the timer has hit
                    {
                        BsonArray affectArray = modFound["Affects"].AsBsonArray;
                        //we want to show the value always as positive to the players, only internally should they be negative
                        foreach (BsonDocument affect in affectArray)
                        {
                            double makePositive = 1;

                            if (affect["Value"].AsDouble < 0)
                            {
                                makePositive = -1;
                            }

                            foreach (string playerid in room.players)
                            {
                                User.User user = MySockets.Server.GetAUser(playerid);

                                if (user != null)
                                {
                                    user.Player.ApplyEffectOnAttribute("Hitpoints", affect["Value"].AsDouble);
                                    user.MessageHandler(String.Format(affect["DescriptionSelf"].AsString, affect["Value"].AsDouble * makePositive));
                                    room.InformPlayersInRoom(String.Format(affect["DescriptionOthers"].AsString, user.Player.FirstName,
                                                                           user.Player.Gender.ToString() == "Male" ? "his" : "her"), new List <string>(new string[] { user.UserID }));
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #6
0
        public void InformPlayersInRoom(string message, List <string> ignoreId)
        {
            if (!string.IsNullOrEmpty(message))
            {
                GetPlayersInRoom();
                foreach (string id in players)
                {
                    if (!ignoreId.Contains(id))
                    {
                        User.User otherUser = MySockets.Server.GetAUser(id);
                        if (otherUser != null && otherUser.CurrentState == User.User.UserState.TALKING)
                        {
                            otherUser.MessageHandler(message);
                        }
                    }
                }

                GetNPCsInRoom();
                foreach (string id in npcs)
                {
                    if (!ignoreId.Contains(id))
                    {
                        User.User otherUser = Character.NPCUtils.GetUserAsNPCFromList(new List <string>(new string[] { id }));
                        if (otherUser != null && otherUser.CurrentState == User.User.UserState.TALKING)
                        {
                            otherUser.MessageHandler(message);
                        }
                    }
                }

                //Here we want to see if this room has any triggers or if any of the exits have any triggers
                CheckRoomTriggers(message);
                GetRoomExits();
                if (RoomExits != null)
                {
                    foreach (Exits exit in RoomExits)
                    {
                        if (exit.doors.Count > 0 && exit.doors[exit.Direction.CamelCaseWord()].Listener)
                        {
                            string methodToCall = exit.doors[exit.Direction.CamelCaseWord()].CheckPhrase(message);
                        }
                    }
                }
            }
        }
コード例 #7
0
ファイル: ScriptMethods.cs プロジェクト: vadian/Novus
 public static void SendMessage(string playerID, string message)
 {
     User.User player = MySockets.Server.GetAUser(playerID);
     player.MessageHandler(message);
 }
コード例 #8
0
ファイル: Group.cs プロジェクト: vadian/Novus
 public void InvitePlayer(string playerName)
 {
     User.User user = MySockets.Server.GetAUserByFullName(playerName);
     user.MessageHandler(string.Format("You have been invited to join the group \"{0}\"", GroupName));
     MySockets.Server.GetAUser(LeaderID).MessageHandler("An invitation to join the group has been sent to " + user.Player.FullName + ".");
 }
コード例 #9
0
ファイル: NPC.cs プロジェクト: vadian/Novus
        public bool Loot(User.User looter, List <string> commands, bool byPassCheck = false)
        {
            bool looted = false;

            if (IsDead())
            {
                List <Items.Iitem> result = new List <Items.Iitem>();
                StringBuilder      sb     = new StringBuilder();

                if (!byPassCheck)
                {
                    //Let's see if who's looting was the killer otherwise we check the time of death
                    //also check if looter is part of a group if so then the group will provide the loot logic.
                    if (!string.Equals(looter.UserID, ((Iactor)this).KillerID, StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (!CanLoot(looter.UserID))
                        {
                            //looter not the killer not in group and time to loot has not expired
                            looter.MessageHandler("You did not deal the killing blow and can not loot this corpse at this time.");
                            return(false);
                        }
                    }


                    //let's check if looter is in a group
                    if (!string.IsNullOrEmpty(looter.GroupName))
                    {
                        //looter is part of a group, let's see if the group loot rule is free for all first
                        Groups.Group group = Groups.Groups.GetInstance().GetGroup(looter.GroupName);
                        if (group.GroupRuleForLooting != Groups.GroupLootRule.First_to_loot)
                        {
                            group.Loot(looter, commands, this);
                            return(false);
                        }
                    }
                }

                if (commands.Contains("all"))
                {
                    sb.AppendLine("You loot the following items from " + FirstName + ":");
                    Inventory.GetInventoryAsItemList().ForEach(i => {
                        sb.AppendLine(i.Name);
                        looter.Player.Inventory.AddItemToInventory(Inventory.RemoveInventoryItem(i, this.Equipment));
                    });

                    looted = true;
                }
                else if (commands.Count > 2)                   //the big one, should allow to loot individual item from the inventory
                {
                    string   itemName       = Items.Items.ParseItemName(commands);
                    int      index          = 1;
                    int      position       = 1;
                    string[] positionString = commands[0].Split('.');                     //we are separating based on using the decimal operator after the name of the npc/item
                    if (positionString.Count() > 1)
                    {
                        int.TryParse(positionString[positionString.Count() - 1], out position);
                    }

                    Inventory.GetInventoryAsItemList().ForEach(i => {
                        if (string.Equals(i.Name, itemName, StringComparison.InvariantCultureIgnoreCase) && index == position)
                        {
                            looter.Player.Inventory.AddItemToInventory(Inventory.RemoveInventoryItem(i, this.Equipment));

                            sb.AppendLine("You loot " + i.Name + " from " + FirstName);
                            Rooms.Room.GetRoom(looter.Player.Location).InformPlayersInRoom(string.Format("{0} loots {1} from {3}'s lifeless body.", looter.Player.FirstName, i.Name, FirstName), new List <string>()
                            {
                                ID
                            });
                            index  = -1;                            //we found it and don't need this to match anymore
                            looted = true;
                        }
                        else
                        {
                            index++;
                        }
                    });
                }
                else
                {
                    sb.AppendLine(FirstName + " was carrying: ");
                    Inventory.GetInventoryAsItemList().ForEach(i => sb.AppendLine(i.Name));
                }

                looter.MessageHandler(sb.ToString());
            }
            return(looted);
        }
コード例 #10
0
        //The group commands will basically follow this following format:
        //group create The Ragtag Squad
        //group invite willy wonka
        //group disband
        //this will further parse the command line and call the appropriate group commands
        public static void Group(User.User player, List <string> commands)
        {
            bool   inGroup = !string.IsNullOrEmpty(player.GroupName);
            string name    = RemoveWords(commands[0]);

            User.User user = null;
            if (commands.Count > 2)
            {
                switch (commands[2])
                {
                case "create":
                    Groups.Groups.GetInstance().CreateGroup(player.UserID, name);
                    break;

                case "disband":
                    Groups.Groups.GetInstance().DisbandGroup(player.UserID, player.GroupName);
                    break;

                case "accept":
                    Groups.Groups.GetInstance().AcceptDenyJoinRequest(player.UserID, name, true);
                    break;

                case "deny":
                    Groups.Groups.GetInstance().AcceptDenyJoinRequest(player.UserID, name, false);
                    break;

                case "promote":
                    user = MySockets.Server.GetAUserByFullName(name);
                    if (user == null)
                    {
                        user = MySockets.Server.GetAUserByFirstName(name).FirstOrDefault();
                    }

                    if (user != null)
                    {
                        Groups.Groups.GetInstance().PromoteToLeader(player.UserID, player.GroupName, user.UserID);
                    }
                    else
                    {
                        player.MessageHandler("No player by that name was found.  If you only used a first name try including the last name as well.");
                    }
                    break;

                case "join":
                    Groups.Groups.GetInstance().Join(player.UserID, name);
                    break;

                case "invite":
                    Groups.Groups.GetInstance().InviteToGroup(player.UserID, name, player.GroupName);
                    break;

                case "decline":
                    Groups.Groups.GetInstance().DeclineInvite(player.UserID, name);
                    break;

                case "uninvite":
                    Groups.Groups.GetInstance().Uninvite(player.UserID, name, player.GroupName);
                    break;

                case "kick":
                case "remove":
                    Groups.Groups.GetInstance().RemovePlayerFromGroup(player.UserID, name, player.GroupName);
                    break;

                case "list":
                    if (string.IsNullOrEmpty(name) || name.ToLower() == "all")
                    {
                        player.MessageHandler(Groups.Groups.GetInstance().GetGroupNameOnlyList());
                    }
                    else
                    {
                        player.MessageHandler(Groups.Groups.GetInstance().GetAllGroupInfo(name));
                    }
                    break;

                case "request":
                    Groups.Groups.GetInstance().RequestGroupJoin(player.UserID, name);
                    break;

                case "master":
                    user = MySockets.Server.GetAUserByFullName(name);
                    if (user == null)
                    {
                        user = MySockets.Server.GetAUserByFirstName(name).FirstOrDefault();
                    }
                    if (user == null)
                    {
                        player.MessageHandler("No player by that name was found.  If you only used a first name try including the last name as well.");
                    }
                    else
                    {
                        Groups.Groups.GetInstance().AssignMasterLooter(player.UserID, name, player.GroupName);
                    }
                    break;

                case "lootrule":
                    Groups.GroupLootRule newRule = Groups.GroupLootRule.Leader_only;
                    switch (commands[3])
                    {
                    case "master":
                        newRule = Groups.GroupLootRule.Master_Looter;
                        break;

                    case "leader":
                        newRule = Groups.GroupLootRule.Leader_only;
                        break;

                    case "chance":
                        newRule = Groups.GroupLootRule.Chance_Loot;
                        break;

                    case "first":
                        newRule = Groups.GroupLootRule.First_to_loot;
                        break;

                    case "next":
                        newRule = Groups.GroupLootRule.Next_player_loots;
                        break;
                    }
                    Groups.Groups.GetInstance().ChangeLootingRule(player.UserID, player.GroupName, newRule);
                    break;

                case "joinrule":
                    Groups.GroupJoinRule joinRule = Groups.GroupJoinRule.Friends_only;
                    if (commands.Count > 3)
                    {
                        switch (commands[3])
                        {
                        case "friends":
                            joinRule = Groups.GroupJoinRule.Friends_only;
                            break;

                        case "open":
                            joinRule = Groups.GroupJoinRule.Open;
                            break;

                        case "request":
                            joinRule = Groups.GroupJoinRule.Request;
                            break;
                        }
                        Groups.Groups.GetInstance().ChangeJoiningRule(player.UserID, player.GroupName, joinRule);
                    }
                    else
                    {
                        player.MessageHandler("What rule do you want to change to?");
                    }
                    break;

                case "visibility":
                    Groups.GroupVisibilityRule visibilityRule = Groups.GroupVisibilityRule.Private;
                    switch (commands[3])
                    {
                    case "private":
                        visibilityRule = Groups.GroupVisibilityRule.Private;
                        break;

                    case "public":
                        visibilityRule = Groups.GroupVisibilityRule.Public;
                        break;
                    }
                    Groups.Groups.GetInstance().ChangeVisibilityRule(player.UserID, player.GroupName, visibilityRule);
                    break;

                case "say":
                    Groups.Groups.GetInstance().Say(name, player.GroupName, player.UserID);
                    break;
                }
            }
            else
            {
                player.MessageHandler("Anything in particular you want to do with a group?");
            }
        }
コード例 #11
0
ファイル: Character.cs プロジェクト: vadian/Novus
        public bool Loot(User.User looter, List <string> commands, bool bypassCheck = false)
        {
            bool looted = false;

            if (IsDead())
            {
                List <Items.Iitem> result = new List <Items.Iitem>();
                StringBuilder      sb     = new StringBuilder();

                if (!bypassCheck)
                {
                    if (CanLoot(looter.UserID))
                    {
                        looter.MessageHandler("You did not deal the killing blow and can not loot this corpse at this time.");
                        return(false);
                    }
                }

                if (commands.Contains("all"))
                {
                    sb.AppendLine("You loot the following items from " + FirstName + ":");
                    Inventory.GetInventoryAsItemList().ForEach(i => {
                        sb.AppendLine(i.Name);
                        looter.Player.Inventory.AddItemToInventory(i);
                    });
                    looted = true;
                }
                else if (commands.Count > 2)   //the big one, should allow to loot individual item from the inventory
                {
                    string   itemName       = Items.Items.ParseItemName(commands);
                    int      index          = 1;
                    int      position       = 1;
                    string[] positionString = commands[0].Split('.'); //we are separating based on using the decimal operator after the name of the npc/item
                    if (positionString.Count() > 1)
                    {
                        int.TryParse(positionString[positionString.Count() - 1], out position);
                    }

                    Inventory.GetInventoryAsItemList().ForEach(i => {
                        if (string.Equals(i.Name, itemName, StringComparison.InvariantCultureIgnoreCase) && index == position)
                        {
                            looter.Player.Inventory.AddItemToInventory(i);
                            sb.AppendLine("You loot " + i.Name + " from " + FirstName);
                            index  = -1; //we found it and don't need this to match anymore
                            looted = true;
                            //no need to break since we are checking on index and I doubt a player will have so many items in their inventory that it will
                            //take a long time to go through each of them
                        }
                        else
                        {
                            index++;
                        }
                    });
                }
                else
                {
                    sb.AppendLine(FirstName + " is carrying: ");
                    Inventory.GetInventoryAsItemList().ForEach(i => sb.AppendLine(i.Name));
                }
            }
            return(looted);
        }