Ejemplo n.º 1
0
        public override InteractResult OnActLeft(InteractionContext context)
        {
            // Try delete tree debris with reduced XP multiplier.
            if (context.HasBlock && context.Block.Get <TreeDebris>() is TreeDebris treeDebris)
            {
                // Create game action pack, compose and try to perform.
                using (var pack = new GameActionPack())
                {
                    // Add debris items to inventory.
                    foreach (var x in ((TreeSpecies)EcoSim.GetSpecies(treeDebris.Species)).DebrisResources)
                    {
                        pack.AddToInventory(context.Player?.User.Inventory, Item.Get(x.Key), x.Value.RandInt, context.Player?.User);
                    }

                    // Create multiblock context with reduced XP multiplier for cleaning debris.
                    var multiblockContext = this.CreateMultiblockContext(context);
                    multiblockContext.ActionDescription    = Localizer.DoStr("clean up tree debris");
                    multiblockContext.ExperiencePerAction *= 0.1f;

                    // Add block deletion to the pack and try to perform it.
                    pack.DeleteBlock(multiblockContext);
                    return((InteractResult)pack.TryPerform());
                }
            }

            // Try interact with a world object.
            if (context.Target is WorldObject)
            {
                return(this.BasicToolOnWorldObjectCheck(context));
            }

            // Fallback (try to damage target).
            return(base.OnActLeft(context));
        }
Ejemplo n.º 2
0
        // temporary solution for hunting without affecting the environment
        // spawn a corpse nearby when a hungry animal becomes visible
        public override void OnBecameVisible(IWorldObserver observer, Animal animal)
        {
            base.OnBecameVisible(observer, animal);

            if (animal.Dead || animal.Hunger < HungerThreshold || !RandomUtil.Chance(ChanceCaughtPreyWhileOffscreen))
            {
                return;
            }

            var preyType = this.GetRegionalPrey(animal);

            if (preyType != null)
            {
                var preySpecies = EcoSim.GetSpecies(preyType.Name) as AnimalSpecies;
                var spawnPos    = (Vector3)animal.Position.WorldPosition3i.SpiralOutXZIter(10).Skip(20)
                                  .Select(x => RouteManager.NearestWalkableY(x, 10)).Where(x => x.IsValid && RouteCacheData.IsFlatGround(x)).FirstOrDefault();
                if (spawnPos != default(Vector3))
                {
                    EcoSim.AnimalSim.SpawnCorpse(preySpecies, spawnPos);
                }
            }
        }
Ejemplo n.º 3
0
        public override InteractResult OnActLeft(InteractionContext context)
        {
            if (context.HasBlock)
            {
                var block = World.GetBlock(context.BlockPosition.Value);
                if (block.Is <TreeDebris>())
                {
                    InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User);
                    //TREE DEBRIS REWARDS
                    (EcoSim.GetSpecies(block.Get <TreeDebris>().Species) as TreeSpecies).DebrisResources.ForEach(x => changes.AddItems(x.Key, x.Value.RandInt));
                    IAtomicAction lawAction = PlayerActions.PickUp.CreateAtomicAction(context.Player.User, Get <WoodPulpItem>(), context.BlockPosition.Value);
                    var           result    = (InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, context.Player.User.Talentset.HasTalent(typeof(LoggingCleanupCrewTalent)) ? 1 : 3, null, changes, lawAction);
                    if (result.IsSuccess)
                    {
                        this.AddExperience(context.Player.User, 0.1f, Localizer.DoStr("removing tree debris"));
                    }
                    return(result);
                }

                if (block.Is <Chopable>())
                {
                    var plant = EcoSim.PlantSim.GetPlant(context.BlockPosition.Value);
                    if (plant != null)
                    {
                        return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false));
                    }
                }
                return(InteractResult.NoOp);
            }

            if (context.Target is WorldObject)
            {
                return(BasicToolOnWorldObjectCheck(context));
            }

            return(base.OnActLeft(context));
        }