Exemplo n.º 1
0
        /// <summary>
        /// Change class information(description only)
        /// </summary>
        /// <param name="ClassType">Type of Class</param>
        /// <param name="ClassNum">Class name</param>
        /// <param name="Description">Old description from Class</param>
        /// <param name="LanguIso">Old Iso language representation from Class</param>
        /// <param name="DescriptionNew">New description of Class</param>
        /// <param name="LanguIsoNew">New Iso language representation of Class</param>
        /// <returns>Success message or <code>null</code> on error</returns>
        public ClassChangeResponse Change(string ClassType, string ClassNum, string Description, string LanguIso, string DescriptionNew, string LanguIsoNew)
        {
            var Change = new ClassChange
            {
                ClassType         = ClassType,
                ClassNum          = ClassNum,
                ClassDescriptions = new Bapi1003Catch[] { new Bapi1003Catch {
                                                              Catchword = Description, LanguIso = LanguIso
                                                          } },
                ClassDescriptionsNew = new Bapi1003CatchNew[] { new Bapi1003CatchNew {
                                                                    Catchword = DescriptionNew, LanguIso = LanguIsoNew
                                                                } },
            };

            return(_sapClass.ClassChange(Change));
        }
        public object PlayerClassSet(LookupKey lookupKey, [FromBody] ClassChange change)
        {
            if (lookupKey.IsInvalid)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.BadRequest, lookupKey.IsIdInvalid ? @"Invalid player id." : @"Invalid player name."
                           ));
            }

            if (change.ClassId == Guid.Empty || ClassBase.Get(change.ClassId) == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, $@"Invalid class id ${change.ClassId}."));
            }

            var(client, player) = Player.Fetch(lookupKey);
            if (player != null)
            {
                player.ClassId = change.ClassId;
                player.RecalculateStatsAndPoints();
                player.UnequipInvalidItems();
                if (player.Online)
                {
                    PacketSender.SendEntityDataToProximity(player);
                }

                using (var context = DbInterface.CreatePlayerContext(false))
                {
                    context.Update(player);
                    context.SaveChanges();
                }

                return(player);
            }

            return(Request.CreateErrorResponse(
                       HttpStatusCode.NotFound,
                       lookupKey.HasId ? $@"No player with id '{lookupKey.Id}'." : $@"No player with name '{lookupKey.Name}'."
                       ));
        }