Esempio n. 1
0
        public Block GetBy(BlockLockRef locref)
        {
            if (locref == null)
            {
                return(null);
            }
            foreach (var b in this)
            {
                if (b == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(b.Name))
                {
                    continue;
                }
                if (b.Occupation == null)
                {
                    continue;
                }
                if (b.Occupation.ObjectId <= 0)
                {
                    continue;
                }

                if (b.Occupation.ObjectId == locref.ObjectId ||
                    b.Occupation.Name.Equals(locref.Name, StringComparison.OrdinalIgnoreCase))
                {
                    return(b);
                }
            }

            return(null);
        }
Esempio n. 2
0
        public bool Parse(JToken tkn)
        {
            var o = tkn as JObject;

            if (o == null)
            {
                return(false);
            }

            try
            {
                if (o["name"] != null)
                {
                    Name = o["name"].ToString();
                }
                if (o["description"] != null)
                {
                    Description = o["description"].ToString();
                }
                if (o["waitMode"] != null)
                {
                    var m = new BlockWaitMode();
                    if (m.Parse(o["waitMode"]))
                    {
                        WaitMode = m;
                    }
                    else
                    {
                        WaitMode = new BlockWaitMode
                        {
                            WaitMin = 1,
                            WaitMax = 60,
                            Mode    = "random"
                        }
                    };
                }

                if (o["exclude"] != null)
                {
                    if (Exclude == null)
                    {
                        Exclude = new List <BlockLockRef>();
                    }

                    var ar = o["exclude"] as JArray;
                    if (ar != null)
                    {
                        for (int i = 0; i < ar.Count; ++i)
                        {
                            var item    = ar[i];
                            var itemObj = new BlockLockRef();
                            if (itemObj.Parse(item))
                            {
                                Exclude.Add(itemObj);
                            }
                        }
                    }
                }

                if (o["locked"] != null)
                {
                    var lockTkn = o["locked"];
                    if (lockTkn != null)
                    {
                        if (lockTkn.Type == JTokenType.String)
                        {
                            var lockV = lockTkn.ToString();
                            if (!string.IsNullOrEmpty(lockV))
                            {
                                Locked = lockV.Equals("true", StringComparison.OrdinalIgnoreCase);
                            }
                            else
                            {
                                Locked = false;
                            }
                        }
                        else if (lockTkn.Type == JTokenType.Boolean)
                        {
                            Locked = (bool)lockTkn;
                        }
                        else if (lockTkn.Type == JTokenType.Integer)
                        {
                            Locked = (int)lockTkn == 1;
                        }
                    }
                }

                if (o["occupation"] != null)
                {
                    var locRef = new BlockLockRef();
                    if (locRef.Parse(o["occupation"]))
                    {
                        Occupation = locRef;
                    }
                }

                if (o["sidePlus"] != null)
                {
                    var arPlus = o["sidePlus"] as JArray;
                    if (arPlus != null)
                    {
                        foreach (var e in arPlus)
                        {
                            if (e == null)
                            {
                                continue;
                            }
                            if (_sidePlusNames.Contains(e.ToString()))
                            {
                                continue;
                            }
                            _sidePlusNames.Add(e.ToString());
                        }
                    }
                }

                if (o["sideMinus"] != null)
                {
                    var arMinus = o["sideMinus"] as JArray;
                    if (arMinus != null)
                    {
                        foreach (var e in arMinus)
                        {
                            if (e == null)
                            {
                                continue;
                            }
                            if (_sideMinusNames.Contains(e.ToString()))
                            {
                                continue;
                            }
                            _sideMinusNames.Add(e.ToString());
                        }
                    }
                }

                if (o["plusEvents"] != null)
                {
                    var evList = new BlockEvents(Ctx);
                    if (evList.Parse(o["plusEvents"]))
                    {
                        PlusEvents = evList;
                    }
                    else
                    {
                        PlusEvents = null;
                    }
                }

                if (o["minusEvents"] != null)
                {
                    var evList = new BlockEvents(Ctx);
                    if (evList.Parse(o["minusEvents"]))
                    {
                        MinusEvents = evList;
                    }
                    else
                    {
                        MinusEvents = null;
                    }
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }