Exemplo n.º 1
0
        /// <summary>
        /// Switch item placements
        /// TODO: catch exceptions
        /// </summary>
        /// <param name="cli">Client</param>
        /// <param name="_from">From location</param>
        /// <param name="_to">To location</param>
        public void switchItems(Client cli, int _from, int _to)
        {
            lock (cli)
            {
                SqlWrapper mySql = new SqlWrapper();
                InventoryEntries afrom = getInventoryAt(_from);
                InventoryEntries ato = getInventoryAt(_to);
                if (afrom != null)
                {
                    afrom.Placement = _to;
                }
                if (ato != null)
                {
                    ato.Placement = _from;
                }

                mySql.SqlUpdate("UPDATE " + getSQLTablefromDynelType() + "inventory SET placement=255 where (ID=" + cli.Character.ID.ToString() + ") AND (placement=" + _from.ToString() + ")");
                mySql.SqlUpdate("UPDATE " + getSQLTablefromDynelType() + "inventory SET placement=" + _from.ToString() + " where (ID=" + cli.Character.ID.ToString() + ") AND (placement=" + _to.ToString() + ")");
                mySql.SqlUpdate("UPDATE " + getSQLTablefromDynelType() + "inventory SET placement=" + _to.ToString() + " where (ID=" + cli.Character.ID.ToString() + ") AND (placement=255)");
            }

            // If its a switch from or to equipment pages then recalculate the skill modifiers
            if ((_from < 64) || (_to < 64))
            {
                CalculateSkills();
            }
        }
        public Tradeskill(Client cli, int src_loc, int tgt_loc)
        {
            Cli = cli;
            SourcePlacement = src_loc;
            TargetPlacement = tgt_loc;
            Source = cli.Character.getInventoryAt(src_loc).Item;
            Target = cli.Character.getInventoryAt(tgt_loc).Item;

            SourceID = Source.highID;
            TargetID = Target.highID;

            isTradeskill = false;

            SqlWrapper wrapper = new SqlWrapper();
            DataTable dt = wrapper.ReadDT("SELECT * FROM tradeskill WHERE ID1 = " + Source.highID + " AND ID2 = " + Target.highID + ";");
            DataRowCollection drc = dt.Rows;

            if (drc.Count > 0)
            {
                isTradeskill = true;
                SourceName = (string)drc[0][3];
                TargetName = (string)drc[0][4];
                ResultName = (string)drc[0][5];
                ResultLID = (int)drc[0][6];
                ResultHID = (int)drc[0][7];
                RangePercent = (int)drc[0][8];
                DeleteFlag = (int)drc[0][9];
                FirstSkill = (int)drc[0][10];
                FirstSkillPercent = (int)drc[0][11];
                FirstSkillPerBump = (int)drc[0][12];
                SecondSkill = (int)drc[0][13];
                SecondSkillPercent = (int)drc[0][14];
                SecondSkillPerBump = (int)drc[0][15];
                MaxBump = (int)drc[0][16];
                MinXP = (int)drc[0][17];
                MaxXP = (int)drc[0][18];

                bDeleteSource = ((DeleteFlag & 1) == 1);
                bDeleteTarget = (((DeleteFlag >> 1) & 1) == 1);

                MinQL = Target.Quality;
                SetMaxQL();

                if (FirstSkill != 0)
                {
                    FirstSkillRequirement = (int)Math.Ceiling((decimal)FirstSkillPercent / 100M * (decimal)Target.Quality);
                    FirstSkillValue = Cli.Character.Stats.GetStatbyNumber(FirstSkill).Value;
                    FirstSkillName = StatsList.GetStatName(FirstSkill);
                }

                if (SecondSkill != 0)
                {
                    SecondSkillRequirement = (int)Math.Ceiling((decimal)SecondSkillPercent / 100M * (decimal)Target.Quality);
                    SecondSkillValue = Cli.Character.Stats.GetStatbyNumber(SecondSkill).Value;
                    SecondSkillName = StatsList.GetStatName(SecondSkill);
                }
            }
        }
        public static void TradeSkillBuildPressed(Client client, int quality)
        {
            int src =
                TradeSkillInfos.Where(m => m.Cli == client && m.Location == 0).Select(m => m).ElementAt(0).Placement;
            int tgt =
                TradeSkillInfos.Where(m => m.Cli == client && m.Location == 1).Select(m => m).ElementAt(0).Placement;

            Tradeskill ts = new Tradeskill(client, src, tgt);

            if (ts.IsTradeSkill)
            {
                ts.Quality = quality;
                ts.WindowBuild();
            }
            else
            {
                client.SendChatText("It is not possible to assemble those two items. Maybe the order was wrong?");
                client.SendChatText("No combination found!");
            }
            TradeSkillInfos.RemoveAll(m => m.Cli == client);
        }
 public TradeSkillInfo(Client cli, int location, int container, int placement)
 {
     this.Cli = cli;
     this.Location = location;
     this.Container = container;
     this.Placement = placement;
 }
        public Tradeskill(Client client, int srcLocation, int targetLocation)
        {
            this.client = client;
            this.sourcePlacement = srcLocation;
            this.targetPlacement = targetLocation;
            this.source = this.client.Character.GetInventoryAt(srcLocation).Item;
            this.target = this.client.Character.GetInventoryAt(targetLocation).Item;

            this.SourceID = this.source.HighID;
            this.TargetID = this.target.HighID;

            this.IsTradeSkill = false;

            SqlWrapper wrapper = new SqlWrapper();
            DataTable dt =
                wrapper.ReadDatatable(
                    "SELECT * FROM tradeskill WHERE ID1 = " + this.source.HighID + " AND ID2 = " + this.target.HighID
                    + ";");
            wrapper.Dispose();
            DataRowCollection drc = dt.Rows;

            if (drc.Count > 0)
            {
                this.IsTradeSkill = true;

                this.sourceName = GetItemName(this.source.LowID, this.source.HighID, this.source.Quality);
                this.targetName = GetItemName(this.target.LowID, this.target.HighID, this.target.Quality);

                this.TargetMinQL = (int)drc[0][2];

                List<int> itemids = new List<int>();

                string[] ItemIDS = ((string)drc[0][3]).Split(',');
                foreach (string id in ItemIDS)
                {
                    itemids.Add(Convert.ToInt32(id.Trim()));
                }

                for (int i = 0; i < itemids.Count / 2; i++)
                {
                    int lowid = itemids.ElementAt(i * 2);
                    int highid = itemids.ElementAt(i * 2 + 1);
                    int lowql = ItemHandler.interpolate(lowid, highid, 1).Quality;
                    int highql = ItemHandler.interpolate(lowid, highid, 300).Quality;
                    this.resultProperties.Add(new TradeSkillResultInfo(lowql, highql, lowid, highid));
                }

                this.rangePercent = (int)drc[0][4];
                this.deleteFlag = (int)drc[0][5];
                string skill = (string)drc[0][6];
                string skillpercent = (string)drc[0][7];
                string skillperbump = (string)drc[0][8];
                this.maxBump = (int)drc[0][9];
                this.minXP = (int)drc[0][10];
                this.maxXP = (int)drc[0][11];
                int isImplant = (int)drc[0][12];

                this.isDeleteSource = ((this.deleteFlag & 1) == 1);
                this.isDeleteTarget = (((this.deleteFlag >> 1) & 1) == 1);

                string[] skills = skill.Split(',');
                string[] skillpercents = skillpercent.Split(',');
                string[] skillperbumps = skillperbump.Split(',');

                this.Skills = new List<TradeSkillSkillInfo>();

                if (skills[0] != string.Empty)
                {
                    for (int i = 0; i < skills.Count(); ++i)
                    {
                        if (skills[0].Trim() != string.Empty)
                        {
                            this.Skills.Add(
                                new TradeSkillSkillInfo(
                                    Convert.ToInt32(skills[i]),
                                    Convert.ToInt32(skillpercents[i]),
                                    Convert.ToInt32(skillperbumps[i]),
                                    this.client.Character.Stats.GetStatbyNumber(Convert.ToInt32(skills[i])).Value,
                                    (int)Math.Ceiling(Convert.ToInt32(skillpercents[i]) / 100M * this.target.Quality),
                                    StatsList.GetStatName(Convert.ToInt32(skills[i]))));
                        }
                    }
                }

                int leastBump = 0;

                if (isImplant > 0)
                {
                    if (this.target.Quality >= 250)
                    {
                        this.maxBump = 5;
                    }
                    else if (this.target.Quality >= 201)
                    {
                        this.maxBump = 4;
                    }
                    else if (this.target.Quality >= 150)
                    {
                        this.maxBump = 3;
                    }
                    else if (this.target.Quality >= 100)
                    {
                        this.maxBump = 2;
                    }
                    else if (this.target.Quality >= 50)
                    {
                        this.maxBump = 1;
                    }
                    else
                    {
                        this.maxBump = 0;
                    }
                }

                foreach (TradeSkillSkillInfo skillinfo in this.Skills)
                {
                    if (skillinfo.PerBump != 0)
                    {
                        leastBump = Math.Min(
                            (skillinfo.Value - skillinfo.Requirement) / skillinfo.PerBump, this.maxBump);
                    }
                }

                this.MinQL = this.target.Quality;
                this.MaxQL = Math.Min(
                    this.target.Quality + leastBump,
                    ItemHandler.interpolate(
                        this.resultProperties.ElementAt(this.resultProperties.Count - 1).LowID,
                        this.resultProperties.ElementAt(this.resultProperties.Count - 1).HighID,
                        300).Quality);

                this.Quality = this.MaxQL;

                this.SetResultIDS(this.Quality);
                this.resultName = GetItemName(this.ResultLowId, this.ResultHighId, this.Quality);
            }
        }
        public static void TradeSkillTargetChanged(Client client, int container, int placement)
        {
            if (container != 0 && placement != 0)
            {
                TradeSkillInfos.Add(new TradeSkillInfo(client, 1, container, placement));

                AOItem it = client.Character.GetInventoryAt(placement).Item;

                TradeskillPacket.SendTarget(client.Character, Tradeskill.TargetProcessesCount(it.HighID));

                var l1 = TradeSkillInfos.Where(m => m.Cli == client && m.Location == 0).Select(m => m);
                var l2 = TradeSkillInfos.Where(m => m.Cli == client && m.Location == 1).Select(m => m);

                if (l1.Count() == 1 && l2.Count() == 1)
                {
                    TradeSkillInfo info1 = l1.ElementAt(0);
                    TradeSkillInfo info2 = l2.ElementAt(0);

                    Tradeskill ts = new Tradeskill(client, info1.Placement, info2.Placement);

                    if (ts.IsTradeSkill)
                    {
                        if (ts.ValidateRange())
                        {
                            foreach (TradeSkillSkillInfo si in ts.Skills)
                            {
                                TradeskillPacket.SendRequirement(client.Character, si);
                            }
                            TradeskillPacket.SendResult(
                                client.Character, ts.MinQL, ts.MaxQL, ts.ResultLowId, ts.ResultHighId);
                        }
                        else
                        {
                            TradeskillPacket.SendOutOfRange(client.Character, ts.sMinQl);
                        }
                    }
                    else
                    {
                        TradeskillPacket.SendNotTradeskill(client.Character);
                    }
                }
            }
            else if (container == 0 && placement == 0)
            {
                TradeSkillInfos.RemoveAll(m => (m.Cli == client) && (m.Location == 1));
            }
        }
Exemplo n.º 7
0
 public bool onTargetinVicinity(Client cli)
 {
     foreach (Statel_Event e in Events)
     {
         if (e.EventNumber != ItemHandler.eventtype_ontargetinvicinity)
         {
             continue;
         }
         if ((AOCoord.distance2D(cli.Character.Coordinates, Coordinates) < 1.2f) && (Math.Abs(cli.Character.Coordinates.y - Coordinates.y) < 5))
         {
             foreach (Statel_Function f in e.Functions)
             {
                 f.Execute(cli, this, e.EventNumber);
             }
             return true;
         }
     }
     return false;
 }
Exemplo n.º 8
0
 public bool onUse(Client cli, Identity target)
 {
     foreach (Statel_Event e in Events)
     {
         if (e.EventNumber != ItemHandler.eventtype_onuse)
         {
             continue;
         }
         if (((UInt32)target.Instance != Instance) || (target.Type != Type))
         {
             continue;
         }
         foreach (Statel_Function f in e.Functions)
         {
             f.Execute(cli, this, e.EventNumber);
         }
         return true;
     }
     return false;
 }
Exemplo n.º 9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="cli"></param>
 /// <param name="stat"></param>
 /// <param name="value"></param>
 /// <param name="announce"></param>
 public void SetStat(Client cli, int stat, uint value, bool announce)
 {
     cli.Character.Stats.SetStatValueByName(stat, value);
 }
Exemplo n.º 10
0
            public void Execute(Client cli, Statel parent, int Eventnumber)
            {
                switch (FunctionNumber)
                {
                    // Hit
                    case 53002:
                        {
                            int statnum = Int32.Parse(Arguments.ElementAt(0));
                            int min = Int32.Parse(Arguments.ElementAt(1));
                            int max = Int32.Parse(Arguments.ElementAt(2));
                            if (min > max)
                            {
                                min = max;
                                max = Int32.Parse(Arguments.ElementAt(1));
                            }
                            Random rnd = new Random();
                            cli.Character.Stats.Set(statnum, (uint)(cli.Character.Stats.Get(statnum) + rnd.Next(min, max)));
                            break;
                        }
                    // Lineteleport
                    //
                    case 53059:
                        {
#if DEBUG
                            Console.WriteLine("Function 53059 (LineTeleport)");
                            Console.WriteLine("Object: " + parent.Type + ":" + parent.Instance);
#endif
                            uint arg2 = UInt32.Parse(Arguments.ElementAt(1)); // Linesegment and playfield (lower word)
                            arg2 = arg2 >> 16;
                            int to_pf = Int32.Parse(Arguments.ElementAt(2));
                            coordheading a = FindEntry(to_pf, (Int32)arg2);
                            if (a.Coordinates.x != -1)
                            {
                                cli.Teleport(a.Coordinates, a.Heading, to_pf);
                                break;
                            }
                            break;
                        }
                    case 53082: // Teleport Proxy
                        {
                            Identity pfinstance = new Identity();
                            pfinstance.Type = Int32.Parse(Arguments.ElementAt(0));
                            pfinstance.Instance = Int32.Parse(Arguments.ElementAt(1));
                            Identity id2 = new Identity();
                            id2.Type = Int32.Parse(Arguments.ElementAt(2));
                            id2.Instance = Int32.Parse(Arguments.ElementAt(3));
                            Identity id3 = new Identity();
                            id3.Type = Int32.Parse(Arguments.ElementAt(4));
                            id3.Instance = Int32.Parse(Arguments.ElementAt(5));

                            SqlWrapper ms = new SqlWrapper();
                            DataTable dt = ms.ReadDT("SELECT * from proxydestinations WHERE playfield=" + pfinstance.Instance);
                            if (dt.Rows.Count == 0)
                            {
#if DEBUG
                                cli.SendChatText("No Destination found for playfield " + pfinstance.Instance);
                                cli.SendChatText("Statel " + parent.Type.ToString() + ":" + parent.Instance.ToString() + " handling " + Eventnumber.ToString() + " Function " + FunctionNumber.ToString() + " " + cli.Character.Coordinates.ToString());
                                foreach (string arg in Arguments)
                                {
                                    cli.SendChatText("Argument: " + arg);
                                }
#endif
                            }
                            else
                            {
                                AOCoord a = new AOCoord();
                                a.x= (Single)dt.Rows[0][1];
                                a.y= (Single)dt.Rows[0][2];
                                a.z = (Single)dt.Rows[0][3];
                                Quaternion q = new Quaternion(0, 0, 0, 0);
                                q.x = (Single)dt.Rows[0][4];
                                q.y = (Single)dt.Rows[0][5];
                                q.z = (Single)dt.Rows[0][6];
                                q.w = (Single)dt.Rows[0][7];
                                cli.TeleportProxy(a, q, pfinstance.Instance, pfinstance, 1, (Int32)parent.Instance, id2, id3);
                            }
                            break;
                        }
                    case 53092: // Bank
                        {
                            Packets.BankOpen.Send(cli);
                            break;
                        }

                    case 53083: // Teleport Proxy 2
                        {

                            Identity pfinstance = new Identity();
                            pfinstance.Type = Int32.Parse(Arguments.ElementAt(0));
                            pfinstance.Instance = Int32.Parse(Arguments.ElementAt(1));
                            int gs = 1;
                            int sg = 0;
                            Identity R = new Identity();
                            R.Type = Int32.Parse(Arguments.ElementAt(2));
                            R.Instance = Int32.Parse(Arguments.ElementAt(3));
                            Identity dest = new Identity();
                            dest.Type = Int32.Parse(Arguments.ElementAt(4));
                            dest.Instance = Int32.Parse(Arguments.ElementAt(5));
                            int to_pf = (Int32)((UInt32)(dest.Instance & 0xffff));
                            int arg2 = (Int32)((UInt32)(dest.Instance >> 16));
                            coordheading a = FindEntry(to_pf, arg2);

                            if (a.Coordinates.x != -1)
                            {
                                cli.TeleportProxy(a.Coordinates, a.Heading, to_pf, pfinstance, gs, sg, R, dest);
                                break;
                            }
                            break;
                        }
                        // Teleport
                    case 53016:
                        {
                            Quaternion q = new Quaternion(0, 1, 0, 0);
                            AOCoord a = new AOCoord();
                            a.x = Int32.Parse(Arguments.ElementAt(0));
                            a.y = Int32.Parse(Arguments.ElementAt(1));
                            a.z = Int32.Parse(Arguments.ElementAt(2));
                            cli.Teleport(a, q, Int32.Parse(Arguments.ElementAt(3)));
                            break;
                        }

                    case 53044:
                        {
                            string text = Arguments.ElementAt(0);
                            Packets.SystemText.Send(cli, text, 0);
                            break;
                        }
                    default:
                        {
#if DEBUG
                            cli.SendChatText("Statel " + parent.Type.ToString() + ":" + parent.Instance.ToString() + " handling " + Eventnumber.ToString() + " Function " + FunctionNumber.ToString() + " " + cli.Character.Coordinates.ToString());
                            foreach (string arg in Arguments)
                            {
                                cli.SendChatText("Argument: " + arg);
                            }
#endif
                            break;
                        }

                }
            }
Exemplo n.º 11
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="client"> </param>
 /// <param name="toSend"></param>
 public void Broadcast(Client client, string toSend)
 {
     Announce.Broadcast(client, toSend);
 }
Exemplo n.º 12
0
 public bool onTargetinVicinity(Client cli)
 {
     foreach (StatelEvent e in this.Events)
     {
         if (e.EventNumber != Constants.EventtypeOnTargetInVicinity)
         {
             continue;
         }
         if ((AOCoord.Distance2D(cli.Character.Coordinates, this.Coordinates) < 1.2f)
             && (Math.Abs(cli.Character.Coordinates.y - this.Coordinates.y) < 5))
         {
             foreach (Statel_Function f in e.Functions)
             {
                 f.Execute(cli, this, e.EventNumber);
             }
             return true;
         }
     }
     return false;
 }
Exemplo n.º 13
0
            public void Execute(Client cli, Statel parent, int Eventnumber)
            {
                bool reqs_met = true;
                int childop = -1;
                Character ftarget = null;
                bool reqresult = true;
                Character chartarget =
                    (Character)FindDynel.FindDynelById(cli.Character.Target.Type, cli.Character.Target.Instance);

                for (int r = 0; r < this.Requirements.Count; r++)
                {
                    switch (this.Requirements[r].Target)
                    {
                        case itemtarget_user:
                            ftarget = cli.Character;
                            break;
                        case itemtarget_wearer:
                            ftarget = cli.Character;
                            break;
                        case itemtarget_target:
                            ftarget = chartarget;
                            break;
                        case itemtarget_fightingtarget:
                            // Fighting target
                            break;
                        case itemtarget_self:
                            ftarget = cli.Character;
                            break;
                        case itemtarget_selectedtarget:
                            ftarget = chartarget;
                            break;
                    }
                    if (ftarget == null)
                    {
                        reqs_met = false;
                        return;
                    }
                    int statval = ftarget.Stats.StatValueByName(this.Requirements[r].AttributeNumber);
                    switch (this.Requirements[r].Operator)
                    {
                        case operator_and:
                            reqresult = ((statval & this.Requirements[r].AttributeValue) != 0);
                            break;
                        case operator_or:
                            reqresult = ((statval | this.Requirements[r].AttributeValue) != 0);
                            break;
                        case operator_equalto:
                            reqresult = (statval == this.Requirements[r].AttributeValue);
                            break;
                        case operator_lessthan:
                            reqresult = (statval < this.Requirements[r].AttributeValue);
                            break;
                        case operator_greaterthan:
                            reqresult = (statval > this.Requirements[r].AttributeValue);
                            break;
                        case operator_unequal:
                            reqresult = (statval != this.Requirements[r].AttributeValue);
                            break;
                        case operator_true:
                            reqresult = (statval != 0);
                            break;
                        case operator_false:
                            reqresult = (statval == 0);
                            break;
                        case operator_bitand:
                            reqresult = ((statval & this.Requirements[r].AttributeValue) != 0);
                            break;
                        case operator_bitor:
                            reqresult = ((statval | this.Requirements[r].AttributeValue) != 0);
                            break;
                        default:
                            reqresult = true;
                            break;
                    }

                    switch (childop)
                    {
                        case operator_and:
                            reqs_met &= reqresult;
                            break;
                        case operator_or:
                            reqs_met |= reqresult;
                            break;
                        case -1:
                            reqs_met = reqresult;
                            break;
                        default:
                            break;
                    }
                    childop = this.Requirements[r].ChildOperator;
                }

                if (!reqs_met)
                {
                    cli.SendChatText("Requirements not met. (better errormessage not coded yet)");
                    return;
                }

                if (
                    !Program.FunctionC.CallFunction(
                        this.FunctionNumber, cli.Character, cli.Character, parent, this.Arguments.ToArray()))
                {
#if DEBUG
                    cli.SendChatText(
                        "Statel " + parent.Type.ToString() + ":" + parent.Instance.ToString() + " handling "
                        + Eventnumber.ToString() + " Function " + this.FunctionNumber.ToString() + " "
                        + cli.Character.Coordinates);
                    foreach (string arg in this.Arguments)
                    {
                        cli.SendChatText("Argument: " + arg);
                    }
#endif
                }
            }
Exemplo n.º 14
0
 public void SpawnToClient(Client cli)
 {
     Packets.NPCSpawn.NPCSpawntoClient(this, cli, false);
 }
 /// <summary>
 /// Spawn NPC to specified client
 /// </summary>
 /// <param name="cli"></param>
 public void SpawnToClient(Client cli)
 {
     NonPlayerCharacterSpawn.SpawnNpcToClient(this, cli, false);
 }