protected override bool OnTake( Unit unit ) { base.OnTake( unit ); if( Type.InfluenceType == null ) { Log.Warning( "InfluenceItem.OnTake: Type.InfluenceType == null" ); return false; } unit.AddInfluence( Type.InfluenceType, Type.InfluenceTime, true ); return true; }
public bool Take( Unit unit ) { bool ret = OnTake( unit ); if( ret ) { unit.SoundPlay3D( Type.SoundTake, .5f, true ); if( EntitySystemWorld.Instance.IsServer() ) Server_SendSoundPlayTakeToAllClients(); Die(); } return ret; }
protected override bool OnTake( Unit unit ) { bool take = base.OnTake( unit ); if( Type.WeaponType != null ) { PlayerCharacter character = unit as PlayerCharacter; if( character != null && character.TakeWeapon( Type.WeaponType ) ) take = true; } else Log.Warning( "WeaponItem.OnTake: Type.WeaponType == null" ); return take; }
public bool Take(Unit unit) { bool ret = OnTake(unit); if (ret) { unit.SoundPlay3D(Type.SoundTake, .5f, true); //After save in the inventory, delete the item //Die(); this.Visible = false; } return ret; }
public SpringWheel(Bone bone, Unit unit, float size, float stiffness, float damping) { this.bone = bone; this.size = size; this.stiffness = stiffness; this.damping = damping; this.unit = unit; originalBonePosition = bone.Position; originalBoneRotation = bone.Rotation; mesh = new MapObjectAttachedMesh(); mesh.MeshName = "Types/Units/AwesomeAircraft/AwesomeAircraftWheel.mesh"; mesh.ScaleOffset = new Vec3(1, 1, 1); mesh.RotationOffset = Quat.Identity; mesh.PositionOffset = bone.GetDerivedPosition(); unit.Attach(mesh); }
protected override bool OnTake( Unit unit ) { bool take = base.OnTake( unit ); //float lifeMax = unit.Type.LifeMax; //if( unit.Life < lifeMax ) //{ // float life = unit.Life + Type.Health; // if( life > lifeMax ) // life = lifeMax; // unit.Life = life; // take = true; //} return unit.Inventory.AddItem(this); }
protected override bool OnTake( Unit unit ) { bool take = base.OnTake( unit ); float lifeMax = unit.Type.LifeMax; if( unit.Life < lifeMax ) { float life = unit.Life + Type.Health; if( life > lifeMax ) life = lifeMax; unit.Life = life; take = true; } return take; }
protected override bool OnTake( Unit unit ) { bool take = base.OnTake( unit ); PlayerCharacter character = unit as PlayerCharacter; if( character != null ) { bool taked = false; bool taked2 = false; if( Type.BulletType != null ) taked = character.TakeBullets( Type.BulletType, Type.BulletCount ); if( Type.BulletType2 != null ) taked2 = character.TakeBullets( Type.BulletType2, Type.BulletCount2 ); if( taked || taked2 ) take = true; } return take; }
protected override void OnTick() { base.OnTick(); if (currentDelay < Type.HomingDelay) { currentDelay += TickDelta; return; } if (target == null) target = AquireNewTarget(); if (target == null) return; if (target.Died) target = AquireNewTarget(); if (target == null) { this.Die(); return; } if (firstTick) { startDistance = (target.Position - Position).LengthFast(); firstTick = false; } Vec3 direction = target.Position - Position; if (direction.LengthFast() < 0.5f) base.Type.Gravity = 9.81f; MomentaryTurnToPositionUpdate(target.Position); Vec3 velocity = Rotation.GetForward().GetNormalizeFast() * Type.Velocity; base.Velocity = velocity; }
private float CalculateAngleTo(Unit unit) { Vec3 dir = (unit.GetInterpolatedPosition() - Position); Radian unitAngle = (Rotation.ToAngles().Yaw) / -57.29578f; Radian needAngle = MathFunctions.ATan(dir.Y, dir.X); Radian diffAngle = needAngle - unitAngle; return Math.Abs(diffAngle); }
protected float GetTaskMoveObjectPriority( Unit obj ) { return 0; }
//protected float GetMoveObjectPriority( Unit obj ) //{ // return 0; //} protected float GetAttackObjectPriority( Unit obj ) { if( ControlledObject == obj ) return 0; if( obj.Intellect == null ) return 0; //RTSConstructor specific if( ControlledObject.Type.Name == "RTSConstructor" ) { if( Faction == obj.Intellect.Faction ) { if( obj.Life < obj.Type.LifeMax ) { Vec3 distance = obj.Position - ControlledObject.Position; float len = distance.LengthFast(); return 1.0f / len + 1.0f; } } } else { if( Faction != null && obj.Intellect.Faction != null && Faction != obj.Intellect.Faction ) { Vec3 distance = obj.Position - ControlledObject.Position; float len = distance.LengthFast(); return 1.0f / len + 1.0f; } } return 0; }
protected virtual void OnControlledObjectChange( Unit oldObject ) { }
/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnRelatedEntityDelete(Entity)"/></summary> protected override void OnRelatedEntityDelete( Entity entity ) { base.OnRelatedEntityDelete( entity ); if( player == entity ) player = null; if( controlledObject == entity ) controlledObject = null; }
protected float GetTaskAttackObjectPriority( Unit obj ) { if( ControlledObject == obj ) return 0; if( obj.Intellect != null ) { if( Faction != obj.Intellect.Faction ) { Vec3 distance = obj.Position - ControlledObject.Position; float len = distance.LengthFast(); return 1.0f / len + 1.0f; } } return 0; }
protected override void OnRelatedEntityDelete( Entity entity ) { base.OnRelatedEntityDelete( entity ); //mainNotActiveUnit destroyed if( mainNotActiveUnit == entity ) { if( !IsSetDeleted ) { if( EntitySystemWorld.Instance.IsServer() || EntitySystemWorld.Instance.IsSingle() ) ServerOrSingle_RestoreMainControlledUnit(); else mainNotActiveUnit = null; } else mainNotActiveUnit = null; } }
protected virtual bool OnTake( Unit unit ) { return false; }
protected override bool OnTake(Unit unit) { bool take = base.OnTake(unit); float armorMax = unit.Type.ArmorMax; //float armornow = unit.Armor; taken = true; OnRender(RendererWorld.Instance.DefaultCamera); if (EngineConsole.Instance != null && Type.RandomArmorValue == true) { string v = "Random Armoritem value: " + Armor.ToString(); EngineConsole.Instance.Print(v); } if (unit.Life > 0f && Type.Armor <= armorMax) { float armor = unit.Armor + Type.Armor; if (armor > armorMax) armor = armorMax; else if (armor < 0f) armor = 0; unit.Armor = armor; take = true; } return take; }
void ServerOrSingle_ChangeMainControlledUnit( Unit unit ) { //Change player controlled unit mainNotActiveUnit = ControlledObject; //send mainNotActiveUnit to clients if( EntitySystemWorld.Instance.IsServer() ) Server_SendMainNotActiveUnitToClients( EntitySystemWorld.Instance.RemoteEntityWorlds ); if( mainNotActiveUnit != null ) { AddRelationship( mainNotActiveUnit ); mainNotActiveUnit.SetIntellect( null, false ); mainNotActiveUnitRestorePosition = mainNotActiveUnit.Position; //disable collision for shapes and save contact groups mainNotActiveUnitShapeContactGroups = new Dictionary<Shape, int>(); foreach( Body body in mainNotActiveUnit.PhysicsModel.Bodies ) { foreach( Shape shape in body.Shapes ) { mainNotActiveUnitShapeContactGroups.Add( shape, shape.ContactGroup ); shape.ContactGroup = (int)ContactGroup.NoContact; } } mainNotActiveUnit.Server_EnableSynchronizationPositionsToClients = false; ControlledObject = unit; unit.SetIntellect( this, false ); unit.Destroying += AlternativeUnitAllowPlayerControl_Destroying; } }
Vec3 FindFreePositionForUnit( Unit unit, Vec3 center ) { Vec3 volumeSize = unit.MapBounds.GetSize() + new Vec3( 2, 2, 0 ); for( float zOffset = 0; ; zOffset += .3f ) { for( float radius = 3; radius < 8; radius += .6f ) { for( float angle = 0; angle < MathFunctions.PI * 2; angle += MathFunctions.PI / 32 ) { Vec3 pos = center + new Vec3( MathFunctions.Cos( angle ), MathFunctions.Sin( angle ), 0 ) * radius + new Vec3( 0, 0, zOffset ); Bounds volume = new Bounds( pos ); volume.Expand( volumeSize * .5f ); Body[] bodies = PhysicsWorld.Instance.VolumeCast( volume, (int)ContactGroup.CastOnlyContact ); if( bodies.Length == 0 ) return pos; } } } }
void Client_ReceiveMainNotActiveUnit( RemoteEntityWorld sender, ReceiveDataReader reader ) { uint networkUIN = reader.ReadVariableUInt32(); if( !reader.Complete() ) return; if( mainNotActiveUnit != null ) mainNotActiveUnit.Visible = true; mainNotActiveUnit = Entities.Instance.GetByNetworkUIN( networkUIN ) as Unit; }
protected override void OnControlledObjectChange( Unit oldObject ) { base.OnControlledObjectChange( oldObject ); if( oldObject != null ) oldObject.Damage -= ControlledObject_Damage; if( ControlledObject != null ) ControlledObject.Damage += ControlledObject_Damage; }
public void TryToChangeMainControlledUnit( Unit unit ) { if( EntitySystemWorld.Instance.IsServer() || EntitySystemWorld.Instance.IsSingle() ) { ServerOrSingle_ChangeMainControlledUnit( unit ); } if( EntitySystemWorld.Instance.IsClientOnly() ) { SendDataWriter writer = BeginNetworkMessage( typeof( PlayerIntellect ), (ushort)NetworkMessages.ChangeMainControlledUnitToServer ); writer.WriteVariableUInt32( unit.NetworkUIN ); EndNetworkMessage(); } }
public void ChangeMainControlledUnit( Unit unit ) { //Change player controlled unit mainNotActiveUnit = ControlledObject; if( mainNotActiveUnit != null ) { AddRelationship( mainNotActiveUnit ); mainNotActiveUnit.Intellect = null; mainNotActiveUnitRestorePosition = mainNotActiveUnit.Position; ControlledObject = unit; unit.Intellect = PlayerIntellect.Instance; unit.Destroying += AlternativeUnitAllowPlayerControl_Destroying; //disable collision for shapes and save contact groups mainNotActiveUnitShapeContactGroups = new Dictionary<Shape, int>(); foreach( Body body in mainNotActiveUnit.PhysicsModel.Bodies ) { foreach( Shape shape in body.Shapes ) { mainNotActiveUnitShapeContactGroups.Add( shape, shape.ContactGroup ); shape.ContactGroup = (int)ContactGroup.NoContact; } } } }
protected override void OnControlledObjectChange( Unit oldObject ) { base.OnControlledObjectChange( oldObject ); //update look direction if( ControlledObject != null ) lookDirection = SphereDir.FromVector( ControlledObject.Rotation * new Vec3( 1, 0, 0 ) ); //TankGame specific { //set small damage for player tank Tank oldTank = oldObject as Tank; if( oldTank != null ) oldTank.ReceiveDamageCoefficient = 1; Tank tank = ControlledObject as Tank; if( tank != null ) tank.ReceiveDamageCoefficient = .1f; } }
void ServerOrSingle_RestoreMainControlledUnit() { if( mainNotActiveUnit == null ) return; if( ControlledObject != null ) { ControlledObject.SetIntellect( null, false ); ControlledObject.Destroying -= AlternativeUnitAllowPlayerControl_Destroying; } if( !mainNotActiveUnit.IsSetDeleted ) { mainNotActiveUnit.Server_EnableSynchronizationPositionsToClients = true; mainNotActiveUnit.Position = mainNotActiveUnitRestorePosition; //find free position for movable player controlled units if( ControlledObject != null ) { //Tank specific if( ControlledObject is Tank ) { mainNotActiveUnit.Position = FindFreePositionForUnit( mainNotActiveUnit, ControlledObject.Position ); } } mainNotActiveUnit.OldPosition = mainNotActiveUnit.Position; mainNotActiveUnit.Visible = true; RemoveRelationship( mainNotActiveUnit ); //restore contact groups for shapes if( mainNotActiveUnitShapeContactGroups != null ) { foreach( Body body in mainNotActiveUnit.PhysicsModel.Bodies ) { foreach( Shape shape in body.Shapes ) { int group; if( mainNotActiveUnitShapeContactGroups.TryGetValue( shape, out group ) ) shape.ContactGroup = group; } } mainNotActiveUnitShapeContactGroups.Clear(); mainNotActiveUnitShapeContactGroups = null; } mainNotActiveUnit.SetIntellect( this, false ); ControlledObject = mainNotActiveUnit; } else ControlledObject = null; mainNotActiveUnit = null; //send mainNotActiveUnit to clients if( EntitySystemWorld.Instance.IsServer() ) Server_SendMainNotActiveUnitToClients( EntitySystemWorld.Instance.RemoteEntityWorlds ); }
/// <summary> /// Overrides the corresponding method from the Item base type. /// </summary> protected override bool OnTake(Unit unit) { bool take; //player faction will be set by selecting a team in gui // flags have faction set in item class if (playerpickup != null) //player pickup should be null prior to picking up which would mean code error or bug return false; if (this.Type.InitialFaction != null || unit.InitialFaction != null) //not a CTF game don't allow pickup { if (this.Type.InitialFaction == unit.InitialFaction) { //can't Take own flag .. for now return false; } else if (this.Type.InitialFaction != unit.InitialFaction) { //TODO: Add your implementation before or after the following base method call take = base.OnTake(unit); this.Type.Taken = true; //add model of object on the unit at Alias position playerpickup = unit; //statically save the player holding this item return take = true; } else return false; } else return false; }
/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnRelatedEntityDelete(Entity)"/></summary> protected override void OnRelatedEntityDelete( Entity entity ) { base.OnRelatedEntityDelete( entity ); if( sourceUnit == entity ) sourceUnit = null; if( reasonObject == entity ) reasonObject = null; }
public bool DropFlagItem(Unit unit) { bool droppeditem; this.Type.DroppedItem = true; //remove flag from player //remove unit form playerpickup droppeditem = true; playerpickup = null; return droppeditem; }
float GetAttackObjectPriority( Unit obj ) { if( ControlledObject == obj ) return 0; if( obj.Intellect == null ) return 0; if( obj.Intellect.Faction == null ) return 0; if( Faction == obj.Intellect.Faction ) return 0; Vec3 distance = obj.Position - ControlledObject.Position; float len = distance.LengthFast(); return 1.0f / len + 1.0f; }
protected virtual bool OnTake(Unit unit) { return(false); }