Beispiel #1
0
        ///////////////////////Util////////////////////////////////
        public bool UseItem(string idOrRid, Critter target)
        {
            var item = this.GetItem(idOrRid);

            if (item == null)
            {
                LogCat.error(string.Format("UseItem error:do not has {0}", idOrRid));
                return(false);
            }

            if (!target.CheckUseItem(item))
            {
                return(false);
            }
            item = item.CanFold() ? this.RemoveItems(item.GetId(), 1)[0] : this.RemoveItem(item);
            if (!target.UseItem(item))
            {
                //失败,加回去
                this.AddItem(item);
                return(false);
            }

            item.Destruct();
            return(true);
        }
Beispiel #2
0
        /////////////////////////////////////////镶嵌物/////////////////////////////////
        public bool EmbedOn(Item item, Item embed)
        {
            if (item == null)
            {
                LogCat.error(string.Format("EmbedOn error: item is null"));
                return(false);
            }

            if (embed == null)
            {
                LogCat.error(string.Format("EmbedOn error: embed is null"));
                return(false);
            }

            if (!item.CheckEmbedOn(embed))
            {
                return(false);
            }
            if (this.RemoveItem(embed) == null)
            {
                LogCat.error("EmbedOn error:can not remove item:{0}", item);
                return(false);
            }

            if (!item.EmbedOn(embed))
            {
                //失败,加回去
                this.AddItem(embed);
                return(false);
            }

            return(true);
        }
        public List <Unit> RecommendCast(Unit sourceUnit, string spellId, List <Unit> targetUnitList, bool isControl)
        {
            if (sourceUnit == null || sourceUnit.IsDead())
            {
                return(null);
            }
            if (targetUnitList == null)
            {
                return(null);
            }
            var cfgSpellData = CfgSpell.Instance.get_by_id(spellId);
            var spellClass   = TypeUtil.GetType(cfgSpellData.class_path_cs);

            if (spellClass == null)
            {
                LogCat.error("spell code is not exist: ", cfgSpellData.class_path_cs);
                return(null);
            }

            List <Unit> newTargetUnitList = new List <Unit>();

            for (var i = 0; i < targetUnitList.Count; i++)
            {
                var targetUnit = targetUnitList[i];
                if (this.__IsUnitMatchCondition(sourceUnit, targetUnit, isControl, cfgSpellData, spellClass))
                {
                    newTargetUnitList.Add(targetUnit);
                }
            }

            return(newTargetUnitList);
        }
        public AbstractEntity AddChildWithoutInit(string childKey, Type childType)
        {
            if (childKey != null && keyToChildDict.ContainsKey(childKey))
            {
                LogCat.error("duplicate add child:{0},{1}", childKey, childType);
                return(null);
            }

            bool isKeyUsingParentIdPool = childKey == null;

            if (isKeyUsingParentIdPool)
            {
                childKey = childKeyIdPool.Get().ToString();
                //再次检查键值
                if (keyToChildDict.ContainsKey(childKey))
                {
                    LogCat.error("duplicate add child:{0},{1}", childKey, childType);
                    return(null);
                }
            }

            var child = PoolCatManagerUtil.Spawn(childType) as AbstractEntity;

            child.key = childKey;
            child.isKeyUsingParentIdPool = isKeyUsingParentIdPool;
            return(AddChild(child));
        }
Beispiel #5
0
        public bool EmbedOff(Item item, Item embed)
        {
            if (item == null)
            {
                LogCat.error(string.Format("EmbedOff error: item is null"));
                return(false);
            }

            if (embed == null)
            {
                LogCat.error(string.Format("EmbedOff error: embed is null"));
                return(false);
            }

            if (!item.CheckEmbedOff(embed))
            {
                return(false);
            }
            if (!item.EmbedOff(embed))
            {
                return(false);
            }
            embed.SetEnv(this);
            this.AddItem(embed);
            return(true);
        }
Beispiel #6
0
        public AbstractComponent AddComponent(AbstractComponent component, string componentKey = null)
        {
            if (componentKey != null)
            {
                component.key = componentKey;
            }
            if (component.key != null && this.keyToComponentDict.ContainsKey(component.key))
            {
                LogCat.error("duplicate add component:", component.key, component.GetType());
                return(null);
            }

            bool isKeyUsingParentIdPool = componentKey == null;

            if (isKeyUsingParentIdPool)
            {
                componentKey = componentKeyIdPool.Get().ToString();
                //再次检查键值
                if (this.keyToComponentDict.ContainsKey(componentKey))
                {
                    LogCat.error("duplicate add component:", component.key, component.GetType());
                    return(null);
                }
            }

            component.key = componentKey;
            component.isKeyUsingParentIdPool = isKeyUsingParentIdPool;
            component.entity = this;


            _AddComponentRelationship(component);
            return(component);
        }
        public AbstractEntity AddChild(AbstractEntity child)
        {
            if (keyToChildDict.ContainsKey(child.key))
            {
                LogCat.error("duplicate add child:{0}", child.key, child.GetType());
                return(null);
            }

            child._parent = this;
            __AddChildRelationship(child);
            return(child);
        }
Beispiel #8
0
        //is_control 是否是控制类技能
        public SpellBase CastSkillByIndex(int index, Unit targetUnit, bool isControl)
        {
            var skillId = this.skillIdList[index];

            if (skillId.IsNullOrWhiteSpace())
            {
                LogCat.error("index error ", index);
                return(null);
            }

            return(this.CastSpell(skillId, targetUnit, isControl));
        }
Beispiel #9
0
        public void Slice()
        {
            List <Tile> _tile_list = new List <Tile>();

            if (atlas_texture != null)
            {
                Vector2 tile_texsel_size = CalculateTileTexelSize();
                int     u_increase       = Mathf.RoundToInt(tile_pixel_size.x + slice_padding.x);
                int     v_increase       = Mathf.RoundToInt(tile_pixel_size.y + slice_padding.y);
                _row_tile_count = 0;
                if (u_increase > 0 && v_increase > 0)
                {
                    for (int v = Mathf.RoundToInt(slice_offset.y);
                         v + tile_pixel_size.y <= atlas_texture.height;
                         v += v_increase, ++_row_tile_count)
                    {
                        for (int u = Mathf.RoundToInt(slice_offset.x);
                             u + tile_pixel_size.x <= atlas_texture.width;
                             u += u_increase)
                        {
                            _tile_list.Add(new Tile()
                            {
                                uv = new Rect(
                                    new Vector2((float)u / atlas_texture.width,
                                                (float)(atlas_texture.height - v - tile_pixel_size.y) / atlas_texture.height), tile_texsel_size)
                            });
                        }
                    }

                    _column_tile_count = _tile_list.Count / _row_tile_count;
                    //Copy data from previous tiles
#if UNITY_EDITOR
                    if (!tile_list.IsNullOrEmpty() && EditorUtility.DisplayDialog("保留之前的tile的属性?", "保留之前的tile的属性?", "Yes", "No"))
#endif
                    {
                        for (int i = 0; i < tile_list.Count && i < _tile_list.Count; ++i)
                        {
                            _tile_list[i].tileColliderData = tile_list[i].tileColliderData;
                            _tile_list[i].argContainer     = tile_list[i].argContainer;
                            _tile_list[i].tilePrefabData   = tile_list[i].tilePrefabData;
                        }
                    }

                    tile_list = _tile_list;
                }
                else
                {
                    LogCat.error(string.Format(" Error while slicing. u_increase = {0},u_increase = {1}", u_increase,
                                               v_increase));
                }
            }
        }
Beispiel #10
0
        /////////////////////////////////////////////////////////////////////////
        public string GetAssetPathByRefId(long refId)
        {
            foreach (var assetPathRef in dict.Values)
            {
                if (assetPathRef.refId == refId)
                {
                    return(assetPathRef.assetPath);
                }
            }

            LogCat.error(string.Format("没有找到ref_id:{0}对应的assetPath", refId));
            return(null);
        }
Beispiel #11
0
        /////////////////////////////////////////装备/////////////////////////////////
        public bool PutOnEquip(string idOrRid, Critter target)
        {
            var item = this.GetItem(idOrRid);

            if (item == null)
            {
                return(false);
            }
            string type1    = item.GetType1();
            string type2    = item.GetType2();
            var    oldEquip = target.GetEquipOfTypes(type1, type2);

            if (oldEquip != null)
            {
                if (!this.TakeOffEquip(oldEquip, target))
                {
                    return(false);
                }
            }

            if (!target.CheckPutOnEquip(item))
            {
                return(false);
            }
            item = item.CanFold() ? this.RemoveItems(item.GetId(), 1)[0] : this.RemoveItem(item);
            if (item == null)
            {
                LogCat.error(string.Format("PutOnEquip error:{0} do not has item:{1}", this, idOrRid));
                return(false);
            }


            if (!target.PutOnEquip(item))
            {
                //失败,加回去
                this.AddItem(item);
                return(false);
            }

            item.Destruct();
            return(true);
        }
Beispiel #12
0
        public bool TakeOffEquip(Item equip, Critter target)
        {
            if (equip == null)
            {
                LogCat.error(string.Format("TakeOffEquip error: equip is null"));
                return(false);
            }

            if (!target.CheckTakeOffEquip(equip))
            {
                return(false);
            }

            if (!target.TakeOffEquip(equip))
            {
                return(false);
            }
            equip.SetEnv(this);
            this.AddItem(equip);
            return(true);
        }
Beispiel #13
0
        public static object ConvertValue(object value, string typeString)
        {
            if (typeString.Equals(DoerAttrParserConst.Type_String_List[0]))
            {
                return(value.ToIntOrToDefault());
            }
            if (typeString.Equals(DoerAttrParserConst.Type_String_List[1]))
            {
                return(value.ToFloatOrToDefault());
            }
            if (typeString.Equals(DoerAttrParserConst.Type_String_List[2]))
            {
                return(value.ToBoolOrToDefault());
            }
            if (typeString.Equals(DoerAttrParserConst.Type_String_List[3]))
            {
                return(value.ToStringOrToDefault(""));
            }

            LogCat.error(string.Format("没有处理该type_string[{0}]的方法", typeString));
            return(null);
        }
Beispiel #14
0
        public List <Unit> RecommendCast(Unit sourceUnit, string spellId, Unit targetUnit, bool isControl)
        {
            if (sourceUnit == null || sourceUnit.IsDead())
            {
                return(null);
            }
            if (targetUnit == null)
            {
                return(null);
            }
            var cfgSpellData = CfgSpell.Instance.get_by_id(spellId);
            var spellClass   = TypeUtil.GetType(cfgSpellData.class_path_cs);

            if (spellClass == null)
            {
                LogCat.error("spell code is not exist: ", cfgSpellData.class_path_cs);
                return(null);
            }

            return(this.__IsUnitMatchCondition(sourceUnit, targetUnit, isControl, cfgSpellData, spellClass) ? new List <Unit>()
            {
                targetUnit
            } : null);
        }
Beispiel #15
0
 public void AddTileSetBrush(TileSetBrush tileSetBrush)
 {
     if (tileSetBrush.tileSet == this)
     {
         if (!tileSetBrush_list.Exists(x => x.tileSetBrush == tileSetBrush))
         {
             int id     = tileSetBrush_list.Count > 0 ? tileSetBrush_list[tileSetBrush_list.Count - 1].id : 1; //NOTE: id 0 is reserved for default brush
             int max_id = (int)TileSetConst.TileDataMask_TileSetBrushId >> 16;
             if (tileSetBrush_list.Count >= max_id)
             {
                 LogCat.error(string.Format(" Max number of brushes reached! {0}", max_id));
             }
             else
             {
                 // find a not used id
                 while (tileSetBrush_list.Exists(x => x.id == id))
                 {
                     ++id;
                     if (id > max_id)
                     {
                         id = 1;
                     }
                 }
                 tileSetBrush_list.Add(new TileSetBrushContainer()
                 {
                     id = id, tileSetBrush = tileSetBrush
                 });
                 tileSetBrush_cache_dcit.Clear();
             }
         }
     }
     else
     {
         Debug.LogWarning(string.Format("This brush {0} has a different tileset and will not be added! ", tileSetBrush.name));
     }
 }
        public BaseAssetAsyncLoader LoadAssetAsync(string assetPath, Action <AssetCat> onLoadSuccessCallback = null,
                                                   Action <AssetCat> onLoadFailCallback = null, Action <AssetCat> onLoadDoneCallback = null,
                                                   object callbackCause = null)
        {
            AssetCat assetCat;

            if (Application.isEditor && EditorModeConst.IsEditorMode ||
                assetPath.Contains(FilePathConst.ResourcesFlag)
                )
            {
                assetCat = __GetOrAddAssetCat(assetPath);
                onLoadSuccessCallback?.Invoke(assetCat);
                onLoadDoneCallback?.Invoke(assetCat);
                return(new EditorAssetAsyncLoader(assetCat));
            }

            var assetBundleName = assetPathMap.GetAssetBundleName(assetPath);

            if (assetBundleName == null)
            {
                LogCat.error(string.Format("{0}没有设置成ab包", assetPath));
            }

            if (assetCatDict.ContainsKey(assetPath))
            {
                assetCat = GetAssetCat(assetPath);
                //已经加载成功
                if (assetCat.IsLoadSuccess())
                {
                    onLoadSuccessCallback?.Invoke(assetCat);
                    onLoadDoneCallback?.Invoke(assetCat);
                    return(null);
                }

                //加载中
                assetCat.AddOnLoadSuccessCallback(onLoadSuccessCallback, callbackCause);
                assetCat.AddOnLoadFailCallback(onLoadFailCallback, callbackCause);
                assetCat.AddOnLoadDoneCallback(onLoadDoneCallback, callbackCause);
                return(assetAsyncloaderProcessingList.Find(assetAsyncloader =>
                                                           assetAsyncloader.assetCat.assetPath.Equals(assetPath)));
            }

            //没有加载
            var assetAsyncLoader = PoolCatManagerUtil.Spawn <AssetAsyncLoader>();

            assetCat = new AssetCat(assetPath);
            __AddAssetCat(assetPath, assetCat);
            //添加对assetAsyncLoader的引用
            assetCat.AddRefCount();
            assetCat.AddOnLoadSuccessCallback(onLoadSuccessCallback, callbackCause);
            assetCat.AddOnLoadFailCallback(onLoadFailCallback, callbackCause);
            assetCat.AddOnLoadDoneCallback(onLoadDoneCallback, callbackCause);

            var assetBundleLoader = __LoadAssetBundleAsync(assetBundleName);

            assetAsyncLoader.Init(assetCat, assetBundleLoader);
            //asset拥有对assetBundle的引用
            var assetBundleCat = assetBundleLoader.assetBundleCat;

            assetBundleCat.AddRefCount();

            assetCat.assetBundleCat = assetBundleCat;

            assetAsyncloaderProcessingList.Add(assetAsyncLoader);
            return(assetAsyncLoader);
        }
Beispiel #17
0
        public object Parse(string eval)
        {
            if (string.IsNullOrEmpty(eval))
            {
                return(null);
            }
            if (eval.EqualsIgnoreCase(StringConst.String_true))
            {
                return(true);
            }
            if (eval.EqualsIgnoreCase(StringConst.String_false))
            {
                return(false);
            }
            if (Regex.IsMatch(eval, "^[+-]?\\d+$"))             //整数
            {
                if (eval.TrimLeft(StringConst.String_Plus).TrimLeft(StringConst.String_Minus).Length > 10)
                {
                    return(eval.TrimLeft(StringConst.String_Plus).To <long>());
                }
                return(eval.TrimLeft(StringConst.String_Plus).To <int>());
            }

            if (Regex.IsMatch(eval, "^[+-]?((\\d+)|(\\d+\\.\\d*)|(\\d*\\.\\d+))([eE]\\d+)?$"))             //浮点数
            {
                return(eval.TrimLeft(StringConst.String_Plus).To <float>());
            }
            if (eval.StartsWith(StringConst.String_NumberSign))             // 直接字符串
            {
                eval = eval.Substring(StringConst.String_NumberSign.Length);
                if (eval.IndexOf(StringConst.String_LeftCurlyBrackets) != -1)
                {
                    return(this.ParseString(eval));
                }
                return(eval);
            }

            string ueval;

            if (eval.IndexOf(StringConst.String_LeftCurlyBrackets) != -1)
            {
                ueval = this.ParseString(eval);
            }
            else
            {
                ueval = eval;
            }

            object o = XLuaManager.instance.luaEnv.LoadString(string.Format("return {0}", ueval)).Call()[0];

            if (o == null)
            {
                LogCat.error(
                    string.Format("执行表达式错误[{0}{1}]", eval,
                                  StringConst.String_Comma + this.GetU() + StringConst.String_Comma + this.GetO() +
                                  StringConst.String_Comma + this.GetE()));
            }
            if (o is Int64)
            {
                o = o.To <int>();
            }
            else if (o is double)
            {
                o = o.To <float>();
            }
            return(o);
        }
Beispiel #18
0
 public static void ShowNotificationAndError(this EditorWindow self, params object[] args)
 {
     self._ShowNotificationAndCallback(() => LogCat.error(args), args);
 }