예제 #1
0
파일: Utility.cs 프로젝트: Daoting/dt
        /// <summary>
        /// hdt  唐忠宝修改
        /// </summary>
        /// <param name="relativePath"></param>
        /// <returns></returns>
        static async Task <StorageFile> GetLocalResourceAsync(string relativePath)
        {
            string      path = string.Format("Files/{0}", (object[])new object[] { relativePath });
            ResourceMap rm   = ResourceManager.Current.MainResourceMap;

            if (rm.ContainsKey(path))
            {
                return(await rm.GetValue(path, ResourceContext.GetForCurrentView()).GetValueAsFileAsync());
            }
            return(null);
        }
예제 #2
0
파일: Entity.cs 프로젝트: Bluegent/MeRpgBot
        public void AddResource(ResourceTemplate resource)
        {
            if (ResourceMap.ContainsKey(resource.Key))
            {
                return;
            }
            ResourceInstance resIn = new ResourceInstance(resource, this);

            ResourceMap.Add(resource.Key, resIn);
            RefreshProperties();
        }
예제 #3
0
파일: Entity.cs 프로젝트: Bluegent/MeRpgBot
        public void AddToResource(string key, double amount)
        {
            if (!ResourceMap.ContainsKey(key))
            {
                return;
            }
            ResourceInstance res = ResourceMap[key];

            Engine.Log().Log($"[{Name}]Generated {amount:0.} {res.Resource.Name}.");
            res.Add(amount);
        }
예제 #4
0
        public bool FromJObject(JObject obj, IGameEngine engine)
        {
            string name            = obj[GcConstants.General.NAME].ToObject <string>();
            int    level           = obj[GcConstants.General.LEVEL].ToObject <int>();
            double currentExp      = obj[GcConstants.General.CURRENT_EXP].ToObject <double>();
            int    attributePoints = obj[GcConstants.General.ATTRIBUTE_POINTS].ToObject <int>();
            bool   isDead          = obj[GcConstants.General.DEAD].ToObject <bool>();
            long   reviveTime      = obj[GcConstants.General.REVIVE_TIME].ToObject <long>();

            IsDead          = isDead;
            ReviveTime      = reviveTime;
            Name            = name;
            Level           = level;
            CurrentExp      = currentExp;
            AttributePoints = attributePoints;
            JToken[] attributesArray = obj[GcConstants.Classes.ATTRIBUTES].ToArray();
            foreach (JToken attribute in attributesArray)
            {
                string key = attribute[GcConstants.General.KEY].ToObject <string>();
                if (Attributes.ContainsKey(key))
                {
                    Attributes[key].FromJObject(attribute.ToObject <JObject>(), Engine);
                }
            }
            JToken[] resourcesArray = obj[GcConstants.Classes.RESOURCES].ToArray();
            foreach (JToken resource in resourcesArray)
            {
                string key = resource[GcConstants.General.KEY].ToObject <string>();
                if (ResourceMap.ContainsKey(key))
                {
                    ResourceMap[key].FromJObject(resource.ToObject <JObject>(), Engine);
                }
            }
            JToken[] skillsArray = obj[GcConstants.Classes.SKILLS].ToArray();
            foreach (JToken skill in skillsArray)
            {
                string key = skill[GcConstants.General.KEY].ToObject <string>();
                if (Skills.ContainsKey(key))
                {
                    Skills[key].FromJObject(skill.ToObject <JObject>(), Engine);
                }
            }
            return(true);
        }
예제 #5
0
 public override BaseProperty GetProperty(string key)
 {
     if (Attributes.ContainsKey(key))
     {
         return(Attributes[key]);
     }
     if (ResourceMap.ContainsKey(key))
     {
         return(ResourceMap[key]);
     }
     if (Stats.ContainsKey(key))
     {
         return(Stats[key]);
     }
     if (BaseValueMap.ContainsKey(key))
     {
         return(BaseValueMap[key]);
     }
     return(null);
 }
예제 #6
0
        public override bool HasProperty(string propertyKey)
        {
            if (Attributes.ContainsKey(propertyKey))
            {
                return(true);
            }
            if (ResourceMap.ContainsKey(propertyKey))
            {
                return(true);
            }
            if (Stats.ContainsKey(propertyKey))
            {
                return(true);
            }
            if (BaseValueMap.ContainsKey(propertyKey))
            {
                return(true);
            }

            return(false);
        }
예제 #7
0
파일: Entity.cs 프로젝트: Bluegent/MeRpgBot
 public ResourceInstance GetResource(string key)
 {
     return(ResourceMap.ContainsKey(key) ? ResourceMap[key] : null);
 }
예제 #8
0
        public override bool Cast(Entity target, string skillKey, bool autocast = false)
        {
            string tryAlias = Engine.GetSkillManager().GetKeyFromAlias(skillKey);

            if (tryAlias == null)
            {
                tryAlias = skillKey;
            }

            SkillInstance skill = Skills.ContainsKey(tryAlias) ? Skills[tryAlias] : null;

            if (skill == null)
            {
                Engine.Log().Log($"[{Name}] You don't have that skill({tryAlias}).");
                //log that you don't have that skill
                return(false);
            }
            if (skill.CooldownFinishTime != 0)
            {
                long seconds = (skill.CooldownFinishTime - Engine.GetTimer().GetNow()) / GameConstants.TickTime;
                Engine.Log().Log($"[{Name}] {skill.Skill.Name} is on cooldown for {seconds} s.");
                return(false);
            }

            if (!Free)
            {
                Engine.Log().Log($"[{Name}] You are busy.");
                return(false);
            }

            if (!ResourceMap.ContainsKey(skill.Values().Cost.Resource.Key))
            {
                Engine.Log().Log($"[{Name}] You don't have \"{skill.Values().Cost.Resource.Name}\".");
                return(false);
            }
            ResourceInstance res    = ResourceMap[skill.Values().Cost.Resource.Key];
            double           amount = Sanitizer.ReplacePropeties(skill.Values().Cost.Amount, this).Resolve().Value.ToDouble();

            if (!res.CanCast(amount))
            {
                Engine.Log().Log($"[{Name}] Not enough {skill.Values().Cost.Resource.Name} for {skill.Skill.Name}.");
                return(false);
            }

            res.Cast(amount);

            Free = false;

            CurrentlyCasting = new SkillCastData(skill, target, this, Engine.GetTimer().GetNow());
            long time = CurrentlyCasting.CastFinishTime - Engine.GetTimer().GetNow();

            if (time >= GameConstants.TickTime * 3)
            {
                string type         = skill.Skill.Type == SkillType.Cast ? "casting" : "channeling";
                string castedFinish = Key.Equals(CurrentlyCasting.Target.Key)
                    ? ""
                    : $" on  {CurrentlyCasting.Target.Name}";
                Engine.Log()
                .Log(
                    $"[{Name}] Started {type} {CurrentlyCasting.Skill.Skill.Name}{castedFinish}.");
            }
            return(true);
        }