Exemple #1
0
        public static bool Prefix(ref TreeEntity __instance, ref INetObject killer)
        {
            var tfe      = new TreeFellEvent(ref __instance, ref killer);
            var tfeEvent = (IEvent)tfe;

            EventManager.CallEvent(ref tfeEvent);

            if (tfe.IsCancelled())
            {
                __instance.RPC("UpdateHP", __instance.Species.TreeHealth);
                return(false);
            }

            return(true);
        }
Exemple #2
0
        public static float BlockDamage(INetObject damager, float damage, AnimalEntity entity)
        {
            // turtle power! (or uhh tortoise power!)
            if (entity.State == AnimalState.Hiding)
            {
                damage /= 4;
                // TODO: sound effect of arrow bouncing off
                if (damager is Player damagerPlayer)
                {
                    damagerPlayer.MsgLoc($"{entity.Species.Name}: Arrow bounced off my shell!");
                }
            }

            return(damage);
        }
    private bool TryDamageUnfelledTree(INetObject damager, float amount, InteractionContext context)
    {
        if (this.health > 0)
        {
            List <IAtomicAction> playerActions = new List <IAtomicAction>();
            if (damager is Player)
            {
                IAtomicAction statAction = PlayerActions.Harvest.CreateAtomicAction(((Player)damager).User, this);
                playerActions.Add(statAction);

                if (!statAction.CanApplyNonDisposing().Notify((Player)damager))
                {
                    // We only want to dispose the action if it is invalid.  Othewise we want to keep it around to possibly apply later.
                    statAction.Dispose();
                    return(false);
                }
                playerActions.Add(new SimpleAtomicAction(() => (context.SelectedItem as ToolItem).AddExperience(context.Player.User, 5 * this.Species.ExperienceMultiplier, Localizer.Format("felling a {0}", this.Species.UILink()))));
            }

            MultiAtomicAction playerAction = new MultiAtomicAction(playerActions);

            // damage trunk
            this.health = Mathf.Max(0, this.health - amount);

            this.RPC("UpdateHP", this.health / this.Species.TreeHealth);

            if (this.health <= 0)
            {
                this.health = 0;
                if (!playerAction.TryApply().Success)
                {
                    throw new Exception("Killing this tree was verified to be legal a moment ago, but is not anymore.");
                }
                this.FellTree(damager);
                EcoSim.PlantSim.KillPlant(this, DeathType.Harvesting);
            }
            else
            {
                playerAction.Dispose(); // Dispose the unused action
            }
            this.Save();
            return(true);
        }
        else
        {
            return(false);
        }
    }
        public bool HasConsistentAccessibility(INetObject obj, AccessModifier access)
        {
            AccessModifier worldAccess = WorldAccess(obj);

            if (worldAccess.IsFamAndAssem)
            {
                if (access.IsFamAndAssem)
                {
                    return(true);
                }
            }
            else if (worldAccess.IsFamOrAssem)
            {
                if (access.IsPrivate || access.IsFamOrAssem)
                {
                    return(true);
                }
            }
            else if (worldAccess.IsAssembly)
            {
                if (access.IsPrivate || access.IsFamAndAssem || access.IsAssembly)
                {
                    return(true);
                }
            }
            else if (worldAccess.IsPrivate)
            {
                if (access.IsPrivate)
                {
                    return(true);
                }
            }
            else if (worldAccess.IsFamily)
            {
                if (access.IsPrivate || (access.IsFamily && !access.IsAssembly) || access.IsFamAndAssem)
                {
                    return(true);
                }
            }
            else if (worldAccess.IsPublic)
            {
                return(true);
            }

            return(false);
        }
Exemple #5
0
        void FinalizeCatch(Player player, INetObject target)
        {
            if (!(target is AnimalEntity animal))
            {
                return;
            }

            animal.Destroy();

            var resourceType = animal.Species.ResourceItemType;

            if (resourceType == null || !player.User.Inventory.TryAddItem(resourceType, player.User).Notify(player))
            {
                return;
            }
            animal.Kill();
        }
Exemple #6
0
    private bool TryDamageBranch(INetObject damager, float amount, InteractionContext context)
    {
        int        branchID = context.Parameters["branch"];
        TreeBranch branch   = this.branches[branchID];

        if (context.Parameters.ContainsKey("leaf"))
        {
            int leafID = context.Parameters["leaf"];

            // damage leaf
            LeafBunch leaf = branch.Leaves[leafID];

            if (leaf.Health > 0)
            {
                leaf.Health = Mathf.Max(0, leaf.Health - amount);

                if (leaf.Health <= 0)
                {
                    leaf.Health = 0;

                    if (RandomUtil.Value < this.Species.SeedDropChance)
                    {
                        var    numSeeds      = (int)this.Species.SeedRange.Max;
                        int    numBonusSeeds = 0;
                        Item[] newSeeds      = new Item[] { };
                        if (numSeeds > 0 && this.Species.SeedItem != null)
                        {
                            var yield = ItemAttribute.Get <YieldAttribute>(this.Species.SeedItem.Type);
                            numBonusSeeds = yield != null?yield.Yield.GetCurrentValueInt(context.Player.User) : 0;

                            context.Player.User.Inventory.TryAddItems(this.Species.SeedItem.Type, numSeeds + numBonusSeeds);
                        }
                    }
                    this.RPC("DestroyLeaves", branchID, leafID);
                }
            }

            this.Save();
            return(true);
        }
        else
        {
            return(this.TryDamageBranch(branch, branchID, amount));
        }
    }
        public AccessModifier WorldAccess(INetObject obj)
        {
            AccessModifier worldAccess = new AccessModifier();

            worldAccess.Add(obj.Access);

            IScope scope = obj.ParentScope;

            while (scope != null)
            {
                if (scope is Symbol)
                {
                    worldAccess.Add(((Symbol)scope).Access);
                }
                scope = scope.ParentScope;
            }

            return(worldAccess);
        }
    public bool TryApplyDamage(INetObject damager, float amount, InteractionContext context)
    {
        // if the tree is really young, just outright uproot and destroy it.
        if (this.GrowthPercent < saplingGrowthPercent)
        {
            EcoSim.PlantSim.UpRootPlant(this);
            this.Destroy();
            return(false);
        }
        else if (context.Parameters == null)
        {
            return(this.TryDamageUnfelledTree(damager, amount, context));
        }
        else if (context.Parameters.ContainsKey("stump"))
        {
            return(this.TryDamageStump(damager, amount, context));
        }
        else if (context.Parameters.ContainsKey("branch"))
        {
            return(this.TryDamageBranch(damager, amount, context));
        }
        else if (context.Parameters.ContainsKey("slice"))
        {
            // trying to slice the tree
            // if there are still branches, damage them instead
            for (int branchID = 0; branchID < this.branches.Length; branchID++)
            {
                var branch = this.branches[branchID];
                if (this.TryDamageBranch(branch, branchID, amount))
                {
                    return(true);
                }
            }

            return(this.TrySliceTrunk(context.Player, context.Parameters["slice"]));
        }
        else
        {
            return(false);
        }
    }
        public override INetObject <INetSerializable> Get()
        {
            INetObject <INetSerializable> obj = base.Get();

            if (SaveHandler.inSync && obj is ISaveElement ise)
            {
                base.Set((INetObject <INetSerializable>)ise.getReplacement());
                return(base.Get());
            }
            else
            {
                if (!SaveHandler.inSync && !(obj is ISaveElement))
                {
                    base.Set((INetObject <INetSerializable>)SaveHandler.RebuildObject(obj));
                    return(base.Get());
                }
                else
                {
                    return(obj);
                }
            }
        }
Exemple #10
0
 public override void SetDamaged(Animal agent, INetObject damager, out bool isRunAway)
 {
     base.SetDamaged(agent, damager, out isRunAway);
     // Defense on player's acting, attack player if he's damaging us
     if (agent.Alertness < Animal.FleeThreshold && damager is Player player)
     {
         // Run to target if it's in a reachable distance (detect range)
         // Otherwise it's too far and better to run away (while animal is running to player, he may kill us)
         if (player.Position.WrappedDistance(agent.GroundPosition) < agent.Species.DetectRange)
         {
             // Make sure we're anger enough for attacking
             agent.Anger = Animal.AngerLevelToAttack * 2f;
             // Follow a new target or continue following previous
             if (agent.Prey == null)
             {
                 // Take a little time for reacting and then run to a target
                 agent.Prey     = player;
                 agent.NextTick = WorldTime.Seconds + 0.5f;
             }
             isRunAway = false;
         }
     }
 }
 public NetReplacable(INetObject <INetSerializable> item)
     : base(item)
 {
 }
    private bool TryDamageBranch(INetObject damager, float amount, InteractionContext context)
    {
        int        branchID = context.Parameters["branch"];
        TreeBranch branch   = this.branches[branchID];

        if (context.Parameters.ContainsKey("leaf"))
        {
            int leafID = context.Parameters["leaf"];

            // damage leaf
            LeafBunch leaf = branch.Leaves[leafID];

            if (leaf.Health > 0)
            {
                List <IAtomicAction> actions = new List <IAtomicAction>();
                if (damager is Player)
                {
                    var action = PlayerActions.HarvestLeaves.CreateAtomicAction((Player)damager, this);
                    actions.Add(action);

                    if (!PlayerActions.HarvestLeaves.CreateAtomicAction((Player)damager, this).CanApply().Notify((Player)damager))
                    {
                        // We only want to dispose the action if it is invalid.  Othewise we want to keep it around to possibly apply later.
                        action.Dispose();
                        return(false);
                    }
                }

                leaf.Health = Mathf.Max(0, leaf.Health - amount);

                if (leaf.Health <= 0)
                {
                    if (!new MultiAtomicAction(actions).TryApply().Success)
                    {
                        throw new Exception("Removing this stump was verified to be legal a moment ago, but is not anymore.");
                    }

                    leaf.Health = 0;

                    if (RandomUtil.Value < this.Species.SeedDropChance)
                    {
                        var    numSeeds      = (int)this.Species.SeedRange.Max;
                        int    numBonusSeeds = 0;
                        Item[] newSeeds      = new Item[] { };
                        if (numSeeds > 0 && this.Species.SeedItem.Type != null)
                        {
                            var yield = ItemAttribute.Get <YieldAttribute>(this.Species.SeedItem.Type);
                            numBonusSeeds = yield != null?yield.Yield.GetCurrentValueInt(context.Player.User) : 0;

                            context.Player.User.Inventory.TryAddItems(this.Species.SeedItem.Type, numSeeds + numBonusSeeds);
                        }
                    }
                    this.RPC("DestroyLeaves", branchID, leafID);
                }
                else
                {
                    new MultiAtomicAction(actions).Dispose();
                }
            }

            this.Save();
            return(true);
        }
        else
        {
            return(this.TryDamageBranch(branch, branchID, amount));
        }
    }
    private bool TryDamageStump(INetObject damager, float amount, InteractionContext context)
    {
        if (this.Fallen && this.stumpHealth > 0)
        {
            List <IAtomicAction> actions = new List <IAtomicAction>();
            if (damager is Player)
            {
                var action = PlayerActions.RemoveStump.CreateAtomicAction(((Player)damager).User, this);
                actions.Add(action);

                if (!action.CanApplyNonDisposing().Notify((Player)damager))
                {
                    // We only want to dispose the action if it is invalid.  Othewise we want to keep it around to possibly apply later.
                    action.Dispose();
                    return(false);
                }
            }

            this.stumpHealth = Mathf.Max(0, this.stumpHealth - amount);

            if (this.stumpHealth <= 0)
            {
                if (!new MultiAtomicAction(actions).TryApply().Success)
                {
                    throw new Exception("Removing this stump was verified to be legal a moment ago, but is not anymore.");
                }

                if (World.GetBlock(this.Position.Round).GetType() == this.Species.BlockType)
                {
                    World.DeleteBlock(this.Position.Round);
                }
                this.stumpHealth = 0;
                //give tree resources
                Player player = (Player)damager;
                if (player != null)
                {
                    InventoryChangeSet changes = new InventoryChangeSet(player.User.Inventory, player.User);
                    var trunkResources         = this.Species.TrunkResources;
                    if (trunkResources != null)
                    {
                        trunkResources.ForEach(x => changes.AddItems(x.Key, x.Value.RandInt));
                    }
                    else
                    {
                        DebugUtils.Fail("Trunk resources missing for: " + this.Species.Name);
                    }
                    changes.TryApply();
                }
                this.RPC("DestroyStump");

                // Let another plant grow here
                EcoSim.PlantSim.UpRootPlant(this);
            }
            else
            {
                new MultiAtomicAction(actions).Dispose();
            }

            this.Save();
            this.CheckDestroy();
            return(true);
        }
        else
        {
            return(false);
        }
    }
Exemple #14
0
 public override Result TryApplyDamage(INetObject damager, float damage, InteractionContext context, Item tool, Type damageDealer = null, float experienceMultiplier = 1f)
 {
     damage = BlockDamage(damager, damage, this);
     return(base.TryApplyDamage(damager, this.State == AnimalState.Hiding ? damage / 4 :  damage, context, tool, damageDealer, experienceMultiplier));
 }
Exemple #15
0
 public void SendEvent(NetworkEvent netEvent, BSONObject bsonObj, INetClient target, INetObject netObj)
 {
     oldManager.SendEvent(netEvent, bsonObj, target, netObj);
 }
Exemple #16
0
 public override Result TryApplyDamage(INetObject damager, float damage, InteractionContext context, Item tool, Type damageDealer = null, float experienceMultiplier = 1f)
 {
     damage = Tortoise.BlockDamage(damager, damage, this);
     return(base.TryApplyDamage(damager, damage, context, tool, damageDealer, experienceMultiplier));
 }
Exemple #17
0
 public TreeFellEvent(ref TreeEntity tree, ref INetObject killer) : base()
 {
     TreeEntity = tree;
     Killer     = killer;
 }
Exemple #18
0
    protected virtual void setData(Dictionary <string, object> data)
    {
        this.mapData = new MapData(data["id"].ToString(), (int)(data["fightMode"]));
        if (data.ContainsKey("playerInitData"))
        {
            this.mapData.playerInitData = new List <object>((object[])data["playerInitData"]);
        }
        this.birthGrids = new BirthGridManager(this);
        this.findEntity = new FindEntityManager(this);
        //TODO:写在这里 容易对比。 后端不用抄setData的方法。
        List <Dictionary <string, object> > netObjectDatas = new List <object>((object[])data["entitys"]).ConvertAll <Dictionary <string, object> >((object obj) => {
            return((Dictionary <string, object>)obj);
        });

        netObjectDatas.Sort((Dictionary <string, object> obj1, Dictionary <string, object> obj2) => {
            return((int)(obj1["type"]) - (int)(obj2["type"]));
        });

        Dictionary <int, INetObject> netObjects = this._netObjects;

        this._netObjects = new Dictionary <int, INetObject>();


        //先生成出netObject
        for (int i = 0, len = netObjectDatas.Count; i < len; i++)
        {
            int        netId = (int)(netObjectDatas[i]["netId"]);
            INetObject obj   = netObjects.ContainsKey(netId) ? netObjects[netId] : null;
            int        type  = (int)(netObjectDatas[i]["type"]);
            if (null != obj && obj.type != type)
            {
                throw new Exception("初始化类型不对!");
            }
            if (null == obj)
            {
                NetObjectFactory.createNetObject(type, this, netId);
            }
            else
            {
                netObjects.Remove(netId);
                this.addNetObject(obj);
            }
        }

        //netObject已经被移除掉了。 此时如果再有就说明恢复过程中有被删除的。这里手动的把它们删除掉!
        foreach (INetObject obj in netObjects.Values)
        {
            Utils.clearObject(obj);
        }


        this.netId          = (int)(data["netId"]);
        this.random.seed    = long.Parse((data["randomSeed"]).ToString());
        this.random.seedNum = (int)(data["randomSeedNum"]);
        this._delayCalls    = (MultiAction)this.getNetObject((int)(data["delayCalls"]));
        this.speedRate      = Convert.ToSingle(data["speedRate"]);
        this.powerGain      = (int)(data["powerGain"]);
        this.killPlayerNum  = (int)(data["killPlayerNum"]);
        if (data.ContainsKey("warnning"))
        {
            this.warnning          = (TimeAction)this.getNetObject((int)(data["warnning"]));
            this.warnning.callBack = this.warningTimeHandler;
        }
        else
        {
            this.warningTimeHandler();
        }
        this.birthBeanController = (BirthBeanController)this.getNetObject((int)(data["birthBeanController"]));
        this.refereeController   = (RefereeController)this.getNetObject((int)(data["refereeController"]));

        this.beans = new List <object>((object[])data["beans"]).ConvertAll <LoopBeanEntity>((object netId) => {
            return((LoopBeanEntity)this.getNetObject((int)(netId)));
        });
        this.persons = new List <object>((object[])data["persons"]).ConvertAll <PersonEntity>((object netId) => {
            return((PersonEntity)this.getNetObject((int)(netId)));
        });
        this.players = new List <object>((object[])data["players"]).ConvertAll <PlayerEntity>((object netId) => {
            return((PlayerEntity)this.getNetObject((int)(netId)));
        });

        this.bullets = new List <object>((object[])data["bullets"]).ConvertAll <BulletEntity>((object netId) => {
            return((BulletEntity)this.getNetObject((int)(netId)));
        });
        this.others = new List <object>((object[])data["others"]).ConvertAll <FightEntity>((object netId) => {
            return((FightEntity)this.getNetObject((int)(netId)));
        });


        //按照type顺序 进行初始化。 优先级 gemo->buff->actionBase->actionCommon->action->entity
        for (int i = 0, len = netObjectDatas.Count; i < len; i++)
        {
            int netId = (int)(netObjectDatas[i]["netId"]);
            this.getNetObject(netId).setData(netObjectDatas[i]);
        }
        this.birthGrids.createBirthGrids();
        ((ClientRunTime)this).localPlayer = (ClientPlayerEntity)this.getPlayer(((ClientRunTime)this).uid);
        //for(int i = 0, len = this.players.Count; i < len; i++) {
        //    ( (ClientPlayerEntity)this.players[i] ).build();
        //}

        //Biggo添加
        if (FightMain.isLocal)
        {
            this.aiController = new AIController(this);
        }


        for (int i = 0, len = this.players.Count; i < len; i++)
        {
            if (this.players[i] != ((ClientRunTime)this).localPlayer)
            {
                this.aiController.openAI(this.players[i], 1);
            }
        }
    }
 public override bool TryApplyDamage(INetObject damager, float damage, InteractionContext context, Type damageDealer = null)
 {
     // turtle power! (or uhh tortoise power!)
     return(base.TryApplyDamage(damager, this.AnimationState == AnimalAnimationState.Hiding ? damage / 4 :  damage, context, damageDealer));
 }