Exemplo n.º 1
0
        /// <summary>
        /// Renders HTML for the info card popups
        /// </summary>
        /// <param name="viewer">entity initiating the command</param>
        /// <returns>the output HTML</returns>
        public override string RenderToInfo(IEntity viewer)
        {
            if (viewer == null)
            {
                return(string.Empty);
            }

            IInanimateTemplate dt   = Template <IInanimateTemplate>();
            StringBuilder      sb   = new StringBuilder();
            StaffRank          rank = viewer.ImplementsType <IPlayer>() ? viewer.Template <IPlayerTemplate>().GamePermissionsRank : StaffRank.Player;

            sb.Append("<div class='helpItem'>");

            sb.AppendFormat("<h3>{0}</h3>", GetDescribableName(viewer));
            sb.Append("<hr />");

            if (Qualities.Count > 0)
            {
                sb.Append("<h4>Qualities</h4>");
                sb.AppendFormat("<div>{0}</div>", string.Join(",", Qualities.Select(q => string.Format("({0}:{1})", q.Name, q.Value))));
            }

            sb.Append("</div>");

            return(sb.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        /// News up an entity with its backing data
        /// </summary>
        /// <param name="backingStore">the backing data</param>
        public Inanimate(IInanimateTemplate backingStore)
        {
            Contents  = new EntityContainer <IInanimate>();
            Qualities = new HashSet <IQuality>();

            TemplateId = backingStore.Id;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Spawn this new into the live world into a specified container
        /// </summary>
        /// <param name="spawnTo">the location/container this should spawn into</param>
        public override void SpawnNewInWorld(IGlobalPosition spawnTo)
        {
            //We can't even try this until we know if the data is there
            IInanimateTemplate bS = Template <IInanimateTemplate>() ?? throw new InvalidOperationException("Missing backing data store on object spawn event.");

            Keywords = bS.Keywords;

            if (string.IsNullOrWhiteSpace(BirthMark))
            {
                BirthMark = LiveCache.GetUniqueIdentifier(bS);
                Birthdate = DateTime.Now;
            }

            Qualities       = bS.Qualities;
            AccumulationCap = bS.AccumulationCap;

            TryMoveTo(spawnTo);

            if (CurrentLocation == null)
            {
                throw new NotImplementedException("Objects can't spawn to nothing");
            }

            UpsertToLiveWorldCache(true);

            KickoffProcesses();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Forces the system to valuate the object type and adds it to the Bases
        /// </summary>
        /// <param name="basis">the item to value</param>
        /// <returns>the new value</returns>
        public decimal MakeValuation(IInanimateTemplate basis)
        {
            IEconomicBasis basi = Bases.FirstOrDefault(bas => bas.ItemType == basis);

            if (basi != null)
            {
                return(basi.Basis * basi.Adjustment);
            }

            int newBaseValue = basis.Name.Length;

            if (basis.Qualities.Any())
            {
                newBaseValue += Math.Max(1, basis.Qualities.Sum(quality => quality.Value));
            }

            EconomicBasis newBasis = new EconomicBasis()
            {
                Adjustment = 1,
                Basis      = newBaseValue,
                ItemType   = basis,
                Trend      = 1
            };

            Bases.Add(newBasis);

            return(newBasis.Basis * newBasis.Adjustment);
        }
Exemplo n.º 5
0
        /// <summary>
        /// News up an entity with its backing data and where to spawn it into
        /// </summary>
        /// <param name="backingStore">the backing data</param>
        /// <param name="spawnTo">where to spawn this into</param>
        public Inanimate(IInanimateTemplate backingStore, IGlobalPosition spawnTo)
        {
            Contents  = new EntityContainer <IInanimate>();
            Qualities = new HashSet <IQuality>();

            TemplateId = backingStore.Id;
            SpawnNewInWorld(spawnTo);
        }
Exemplo n.º 6
0
        public ActionResult RemoveDescriptive(long id, string authorize)
        {
            string message = string.Empty;

            if (string.IsNullOrWhiteSpace(authorize))
            {
                message = "You must check the proper authorize radio button first.";
            }
            else
            {
                ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());
                string[]        values     = authorize.Split(new string[] { "|||" }, StringSplitOptions.RemoveEmptyEntries);

                if (values.Count() != 2)
                {
                    message = "You must check the proper authorize radio button first.";
                }
                else
                {
                    string type   = values[0];
                    string phrase = values[1];

                    IInanimateTemplate obj = TemplateCache.Get <IInanimateTemplate>(id);

                    if (obj == null)
                    {
                        message = "That does not exist";
                    }
                    else
                    {
                        GrammaticalType grammaticalType    = (GrammaticalType)Enum.Parse(typeof(GrammaticalType), type);
                        ISensoryEvent   existingOccurrence = obj.Descriptives.FirstOrDefault(occurrence => occurrence.Event.Role == grammaticalType &&
                                                                                             occurrence.Event.Phrase.Equals(phrase, StringComparison.InvariantCultureIgnoreCase));

                        if (existingOccurrence != null)
                        {
                            obj.Descriptives.Remove(existingOccurrence);

                            if (obj.Save(authedUser.GameAccount, authedUser.GetStaffRank(User)))
                            {
                                LoggingUtility.LogAdminCommandUsage("*WEB* - Inanimate RemoveDescriptive[" + id.ToString() + "|" + type.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
                                message = "Delete Successful.";
                            }
                            else
                            {
                                message = "Error; Removal failed.";
                            }
                        }
                        else
                        {
                            message = "That does not exist";
                        }
                    }
                }
            }

            return(RedirectToRoute("ModalErrorOrClose", new { Message = message }));
        }
Exemplo n.º 7
0
        public ActionResult AddEditDescriptive(long id, OccurrenceViewModel vModel)
        {
            string          message    = string.Empty;
            ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());

            IInanimateTemplate obj = TemplateCache.Get <IInanimateTemplate>(id);

            if (obj == null)
            {
                message = "That does not exist";
                return(RedirectToRoute("ModalErrorOrClose", new { Message = message }));
            }

            ISensoryEvent existingOccurrence = obj.Descriptives.FirstOrDefault(occurrence => occurrence.Event.Role == vModel.SensoryEventDataObject.Event.Role &&
                                                                               occurrence.Event.Phrase.Equals(vModel.SensoryEventDataObject.Event.Phrase, StringComparison.InvariantCultureIgnoreCase));

            if (existingOccurrence == null)
            {
                existingOccurrence = new SensoryEvent(vModel.SensoryEventDataObject.SensoryType)
                {
                    Strength = vModel.SensoryEventDataObject.Strength,
                    Event    = new Lexica(vModel.SensoryEventDataObject.Event.Type,
                                          vModel.SensoryEventDataObject.Event.Role,
                                          vModel.SensoryEventDataObject.Event.Phrase, new LexicalContext(null))
                    {
                        Modifiers = vModel.SensoryEventDataObject.Event.Modifiers
                    }
                };
            }
            else
            {
                existingOccurrence.Strength    = vModel.SensoryEventDataObject.Strength;
                existingOccurrence.SensoryType = vModel.SensoryEventDataObject.SensoryType;
                existingOccurrence.Event       = new Lexica(vModel.SensoryEventDataObject.Event.Type,
                                                            vModel.SensoryEventDataObject.Event.Role,
                                                            vModel.SensoryEventDataObject.Event.Phrase, new LexicalContext(null))
                {
                    Modifiers = vModel.SensoryEventDataObject.Event.Modifiers
                };
            }

            obj.Descriptives.RemoveWhere(occurrence => occurrence.Event.Role == vModel.SensoryEventDataObject.Event.Role &&
                                         occurrence.Event.Phrase.Equals(vModel.SensoryEventDataObject.Event.Phrase, StringComparison.InvariantCultureIgnoreCase));

            obj.Descriptives.Add(existingOccurrence);

            if (obj.Save(authedUser.GameAccount, authedUser.GetStaffRank(User)))
            {
                LoggingUtility.LogAdminCommandUsage("*WEB* - Inanimate AddEditDescriptive[" + obj.Id.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
            }
            else
            {
                message = "Error; Edit failed.";
            }

            return(RedirectToRoute("ModalErrorOrClose", new { Message = message }));
        }
Exemplo n.º 8
0
        /// <summary>
        /// What will the merchant buy this item for
        /// </summary>
        /// <param name="item">the item in question</param>
        /// <returns>the price, -1 indicates they wont buy it</returns>
        public int HaggleCheck(IInanimate item)
        {
            decimal value = -1;

            if (item != null)
            {
                IInanimateTemplate template = item.Template <IInanimateTemplate>();
                if (WillPurchase.Any(merch => merch.Item.Id == item.TemplateId))
                {
                    DataStructure.Gaia.IEconomy theEconomy = CurrentLocation.CurrentZone.GetWorld().Macroeconomy;

                    if (theEconomy != null)
                    {
                        DataStructure.Gaia.IEconomicBasis priceBasis = theEconomy.Bases.FirstOrDefault(basis => basis.ItemType.Id == item.TemplateId);

                        if (priceBasis != null)
                        {
                            value = priceBasis.Basis * priceBasis.Adjustment;
                        }
                        else
                        {
                            value = theEconomy.MakeValuation(template);
                        }

                        foreach (IQuality quality in item.Qualities)
                        {
                            DataStructure.Gaia.IEconomicTrend trend = theEconomy.Trends.FirstOrDefault(trnd => trnd.Quality.Equals(quality.Name, StringComparison.InvariantCultureIgnoreCase));

                            if (trend != null)
                            {
                                value += trend.Basis * trend.Adjustment;
                            }
                            else
                            {
                                value += theEconomy.MakeValuation(template);
                            }
                        }

                        decimal myAdjustments = 1;

                        foreach (IMerchandise adjustment in WillPurchase.Where(merch => merch.Item.Id == item.TemplateId))
                        {
                            if (string.IsNullOrWhiteSpace(adjustment.Quality) || item.Qualities.Any(quality => quality.Name.Equals(adjustment.Quality) &&
                                                                                                    quality.Value.IsBetweenOrEqual(adjustment.QualityRange.Low, adjustment.QualityRange.High)))
                            {
                                myAdjustments += adjustment.MarkRate;
                            }
                        }

                        value += value * myAdjustments;
                    }
                }
            }

            return((int)Math.Truncate(value));
        }
Exemplo n.º 9
0
        public ActionResult Remove(long removeId = -1, string authorizeRemove = "", long unapproveId = -1, string authorizeUnapprove = "")
        {
            string message;

            if (!string.IsNullOrWhiteSpace(authorizeRemove) && removeId.ToString().Equals(authorizeRemove))
            {
                ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());

                IInanimateTemplate obj = TemplateCache.Get <IInanimateTemplate>(removeId);

                if (obj == null)
                {
                    message = "That does not exist";
                }
                else if (obj.Remove(authedUser.GameAccount, authedUser.GetStaffRank(User)))
                {
                    LoggingUtility.LogAdminCommandUsage("*WEB* - RemoveInanimate[" + removeId.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
                    message = "Delete Successful.";
                }
                else
                {
                    message = "Error; Removal failed.";
                }
            }
            else if (!string.IsNullOrWhiteSpace(authorizeUnapprove) && unapproveId.ToString().Equals(authorizeUnapprove))
            {
                ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());

                IInanimateTemplate obj = TemplateCache.Get <IInanimateTemplate>(unapproveId);

                if (obj == null)
                {
                    message = "That does not exist";
                }
                else if (obj.ChangeApprovalStatus(authedUser.GameAccount, authedUser.GetStaffRank(User), ApprovalState.Returned))
                {
                    LoggingUtility.LogAdminCommandUsage("*WEB* - UnapproveInanimate[" + unapproveId.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
                    message = "Unapproval Successful.";
                }
                else
                {
                    message = "Error; Unapproval failed.";
                }
            }
            else
            {
                message = "You must check the proper remove or unapprove authorization radio button first.";
            }

            return(RedirectToAction("Index", new { Message = message }));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Executes this command
        /// </summary>
        internal override bool ExecutionBody()
        {
            IInanimateTemplate newObject = (IInanimateTemplate)Subject;
            IMobile            initator  = (IMobile)Actor;
            List <string>      sb        = new List <string>();
            IInanimate         entityObject;

            //No target = spawn to inventory
            if (Target != null)
            {
                IGlobalPosition spawnTo = (IGlobalPosition)Target;
                entityObject = Activator.CreateInstance(newObject.EntityClass, new object[] { newObject }) as IInanimate;
                sb.Add(string.Format("{0} spawned to {1}.", entityObject.TemplateName, spawnTo.CurrentZone.Keywords[0]));
            }
            else
            {
                entityObject = Activator.CreateInstance(newObject.EntityClass, new object[] { newObject, initator.GetContainerAsLocation() }) as IInanimate;
                sb.Add(string.Format("{0} spawned to your inventory.", entityObject.TemplateName));
            }

            //TODO: keywords is janky, location should have its own identifier name somehow for output purposes - DISPLAY short/long NAME

            ILexicalParagraph toActor = new LexicalParagraph(sb.ToString());

            ILexicalParagraph toOrigin = new LexicalParagraph("$S$ appears in the $T$.");

            ILexicalParagraph toSubject = new LexicalParagraph("You are ALIVE");

            ILexicalParagraph toTarget = new LexicalParagraph("You have been given $S$");

            Message messagingObject = new Message(toActor)
            {
                ToOrigin = new List <ILexicalParagraph> {
                    toOrigin
                },
                ToSubject = new List <ILexicalParagraph> {
                    toSubject
                },
                ToTarget = new List <ILexicalParagraph> {
                    toTarget
                }
            };

            messagingObject.ExecuteMessaging(Actor, entityObject, OriginLocation.CurrentZone, OriginLocation.CurrentZone, null);

            return(true);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Adjust the bases
        /// </summary>
        public void Adjust(IInanimateTemplate basis, decimal movement)
        {
            IEnumerable <IEconomicBasis> myBases = Bases.Where(basi => basi.ItemType == basis);

            foreach (IEconomicBasis basi in myBases)
            {
                basi.Adjustment *= movement;

                if (movement > 1)
                {
                    basi.Trend += 1;
                }
                else if (movement < 1)
                {
                    basi.Trend -= 1;
                }
            }
        }
Exemplo n.º 12
0
        public ActionResult Add(AddEditInanimateTemplateViewModel vModel)
        {
            ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());

            IInanimateTemplate newObj = vModel.DataObject;
            string             message;

            if (newObj.Create(authedUser.GameAccount, authedUser.GetStaffRank(User)) == null)
            {
                message = "Error; Creation failed.";
            }
            else
            {
                LoggingUtility.LogAdminCommandUsage("*WEB* - AddInanimateTemplate[" + newObj.Id.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
                message = "Creation Successful.";
            }

            return(RedirectToAction("Index", new { Message = message }));
        }
Exemplo n.º 13
0
        public ActionResult AddEditDescriptive(long id, short descriptiveType, string phrase)
        {
            string message = string.Empty;

            IInanimateTemplate obj = TemplateCache.Get <IInanimateTemplate>(id);

            if (obj == null)
            {
                message = "That does not exist";
                return(RedirectToRoute("ModalErrorOrClose", new { Message = message }));
            }

            OccurrenceViewModel vModel = new OccurrenceViewModel
            {
                AuthedUser    = UserManager.FindById(User.Identity.GetUserId()),
                DataObject    = obj,
                AdminTypeName = "Inanimate"
            };

            if (descriptiveType > -1)
            {
                GrammaticalType grammaticalType = (GrammaticalType)descriptiveType;
                vModel.SensoryEventDataObject = obj.Descriptives.FirstOrDefault(occurrence => occurrence.Event.Role == grammaticalType &&
                                                                                occurrence.Event.Phrase.Equals(phrase, StringComparison.InvariantCultureIgnoreCase));
            }

            if (vModel.SensoryEventDataObject != null)
            {
                vModel.LexicaDataObject = vModel.SensoryEventDataObject.Event;
            }
            else
            {
                vModel.SensoryEventDataObject = new SensoryEvent
                {
                    Event = new Lexica()
                };
            }

            return(View("~/Views/GameAdmin/Inanimate/SensoryEvent.cshtml", "_chromelessLayout", vModel));
        }
Exemplo n.º 14
0
        public ActionResult Edit(int id, AddEditInanimateTemplateViewModel vModel)
        {
            ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());

            IInanimateTemplate obj = TemplateCache.Get <IInanimateTemplate>(id);
            string             message;

            if (obj == null)
            {
                message = "That does not exist";
                return(RedirectToAction("Index", new { Message = message }));
            }

            obj.Name                = vModel.DataObject.Name;
            obj.AccumulationCap     = vModel.DataObject.AccumulationCap;
            obj.Components          = vModel.DataObject.Components;
            obj.Descriptives        = vModel.DataObject.Descriptives;
            obj.InanimateContainers = vModel.DataObject.InanimateContainers;
            obj.MobileContainers    = vModel.DataObject.MobileContainers;
            obj.Model               = vModel.DataObject.Model;
            obj.Produces            = vModel.DataObject.Produces;
            obj.Qualities           = vModel.DataObject.Qualities;
            obj.SkillRequirements   = vModel.DataObject.SkillRequirements;

            if (obj.Save(authedUser.GameAccount, authedUser.GetStaffRank(User)))
            {
                LoggingUtility.LogAdminCommandUsage("*WEB* - EditInanimateTemplate[" + obj.Id.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
                message = "Edit Successful.";
            }
            else
            {
                message = "Error; Edit failed.";
            }

            return(RedirectToAction("Index", new { Message = message }));
        }
Exemplo n.º 15
0
        /// <summary>
        /// Executes this command
        /// </summary>
        public override void Execute()
        {
            List <string> sb = new List <string>();

            if (!(Actor is IContains actorContainer))
            {
                RenderError("You can't craft if you don't have an inventory.");
                return;
            }

            //We're after a list, not the actual command here
            if (Subject != null)
            {
                IEnumerable <IInanimateTemplate> itemsToMake = TemplateCache.GetAll <IInanimateTemplate>().Where(item => item.Produces > 0 && item.Components.Count() > 0);

                //Just a full list of all the things we can make then
                if (Target == null)
                {
                    foreach (IInanimateTemplate item in itemsToMake)
                    {
                        IEnumerable <IInanimate> myItems = actorContainer.GetContents <IInanimate>();
                        if (item.Components.Any(component => myItems.Any(myItem => myItem.TemplateId == component.Item.Id)))
                        {
                            sb.Add(item.RenderBlueprints(Actor));
                        }
                    }
                }
                else
                {
                    //A list of everything that matches keyword
                    string keyword = Target.ToString();

                    foreach (IInanimateTemplate item in itemsToMake.Where(itm => itm.Name.Contains(keyword)))
                    {
                        sb.Add(item.RenderBlueprints(Actor));
                    }
                }

                ILexicalParagraph toActor = new LexicalParagraph(sb.ToString());

                Message messagingObject = new Message(toActor);

                messagingObject.ExecuteMessaging(Actor, null, null, null, null);

                return;
            }

            IInanimateTemplate itemToMake = (IInanimateTemplate)Target;

            string errorCrafting = itemToMake.Craft(Actor);

            if (!string.IsNullOrWhiteSpace(errorCrafting))
            {
                RenderError(errorCrafting);
            }
            else
            {
                sb.Add(string.Format("You craft {0} {1}{2}.", itemToMake.Produces, itemToMake.Name, itemToMake.Produces > 1 ? "s" : ""));

                ILexicalParagraph toActor = new LexicalParagraph(sb.ToString());

                ILexicalParagraph toOrigin = new LexicalParagraph(string.Format("$A$ crafts {0} {1}{2}.", itemToMake.Produces, itemToMake.Name, itemToMake.Produces > 1 ? "s" : ""));

                Message messagingObject = new Message(toActor)
                {
                    ToOrigin = new List <ILexicalParagraph> {
                        toOrigin
                    }
                };

                messagingObject.ExecuteMessaging(Actor, null, null, OriginLocation.CurrentZone, null);

                Actor.Save();
            }

            return;
        }
Exemplo n.º 16
0
 public InanimateComponent(IInanimateTemplate item, int amount)
 {
     Amount = amount;
     Item   = item;
 }