Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////////////
- class KHRWeapon extends UDKWeapon;
- var byte InventoryGroup; // Grupo de inventario. Se usa para cambiar de arma
- // ****************************************************************
- // Instant HIT
- // ****************************************************************
- var ParticleSystem BeamTemplate; // Sistema de partículas del rayo mostrado en Instant Hit
- var MaterialInterface ExplosionDecal; // Decal (calcomanía) que deja en las superficies el Instant Hit
- var float DecalWidth, DecalHeight; // Ancho y altura del decal
- var float DurationOfDecal; // Duraci del decal antes de desaparecer
- var name DecalDissolveParamName; // Nombre del par疥etro del MaterialInstance para disolver el material
- var bool HiddenKey;
- var int AttackValue;
- var int MagicValue;
- // ****************************************************************
- // Animation Variables
- // ****************************************************************
- var array <Name> SwingAnimations; // Nombres de las animaciones a usar
- var array <float> SwingIntervals; // Intervalos de tiempo de cada animacion
- var int currentSwing; // Animacion actual
- var SoundCue SwingSound; // Sonido de espadazo
- // ****************************************************************
- // Weapon Location
- // ****************************************************************
- // Determina la posici real del arma
- simulated event SetPosition(UDKPawn Holder)
- {
- local SkeletalMeshComponent weaponMesh;
- local SkeletalMeshSocket socket;
- local Vector FinalLocation;
- weaponMesh = Holder.Mesh;
- if (weaponMesh != none)
- {
- socket = weaponMesh.GetSocketByName('RightWeapon');
- if (socket != none)
- {
- FinalLocation = weaponMesh.GetBoneLocation(socket.BoneName);
- }
- }
- SetLocation(FinalLocation);
- }
- // Calcula la posici real desde donde se disparan los proyectiles
- simulated event vector GetPhysicalFireStartLoc(optional vector AimDir)
- {
- local SkeletalMeshComponent weaponMesh;
- local SkeletalMeshSocket socket;
- weaponMesh = Instigator.Mesh;
- if (weaponMesh != none)
- {
- socket = weaponMesh.GetSocketByName('RightWeapon');
- if (socket != none)
- {
- return weaponMesh.GetBoneLocation(socket.BoneName);
- }
- }
- }
- // Sobreescribe la funcion de Weapon. Procesa los impactos instantaneos.
- simulated function ProcessInstantHit(byte FiringMode, ImpactInfo Impact, optional int NumHits)
- {
- local MaterialInstanceTimeVarying MITV_Decal;
- // Calcula el da total y lo aplica al actor
- Super.ProcessInstantHit(FiringMode, Impact, NumHits);
- // Creaci del Decal
- MITV_Decal = new(self) class'MaterialInstanceTimeVarying';
- MITV_Decal.SetParent(ExplosionDecal);
- WorldInfo.MyDecalManager.SpawnDecal(MITV_Decal, Impact.HitLocation, rotator(-Impact.HitNormal), DecalWidth, DecalHeight, 10.0, FALSE );
- MITV_Decal.SetScalarStartTime( DecalDissolveParamName, DurationOfDecal );
- }
- // Se llama al equipar el arma
- simulated function TimeWeaponEquipping()
- {
- AttachWeaponTo( Instigator.Mesh,'RightWeapon' );
- super.TimeWeaponEquipping();
- }
- // Acopla el arma a la malla del pawn
- simulated function AttachWeaponTo( SkeletalMeshComponent MeshComp, optional Name SocketName )
- {
- MeshComp.AttachComponentToSocket(Mesh,SocketName);
- Mesh.SetLightEnvironment(KHRPawn(Instigator).LightEnvironment);
- }
- // Llamado al dejar de usar el arma
- simulated function DetachWeapon()
- {
- Instigator.Mesh.DetachComponent(Mesh);
- SetBase(None);
- SetHidden(True);
- HiddenKey = !HiddenKey;
- if(HiddenKey == false)
- {
- }
- else
- {
- }
- }
- // ****************************************************************
- // Weapon Animation
- // ****************************************************************
- // Se sobreescribe para evitar que al soltar el boton se desactive cualquier ataque
- simulated function StopFire(byte FireModeNum);
- // Disparo efectivo
- simulated function FireAmmunition()
- {
- // Se declara que el ataque se ha cumplido
- Super.StopFire(CurrentFireMode);
- // Se elimina posible Timer de reseteo del sistema de melee
- ClearTimer(nameof(ResetMelee));
- // Animacion de melee (AnimName, Rate, BlendInTime, BlendOutTime, bLooping, bOverride)
- KHRPawn(Owner).MeleeAnimNode.PlayCustomAnim(SwingAnimations[currentSwing], 1.0,0.05,0.1,false,true);
- // Efectos
- SpawnSwingEffects();
- // Se reprograma el intervalo de RefireCheckTimer adecuadamente
- FireInterval[0] = SwingIntervals[currentSwing];
- TimeWeaponFiring(CurrentFireMode);
- // Aumenta el indice de las animaciones para pasar a la siguiente
- currentSwing = (currentSwing + 1) % SwingAnimations.length;
- // Se desactiva el desplazamiento del Pawn
- KHRPlayerController(Pawn(Owner).Controller).SetRotationOnly(true);
- Super.FireAmmunition();
- }
- // Programa un timer para llamar a RefireCheckTimer
- simulated function TimeWeaponFiring( byte FireModeNum )
- {
- // Si desde que se inicio el ataque anterior se ha pulsado otra vez clic, RefireCheckTimer volvera a
- // lanzar un ataque, pues PendingFire sera = 1
- SetTimer( GetFireInterval(FireModeNum), false, nameof(RefireCheckTimer) );
- }
- // Llamado al desactivar este arma
- simulated function PutDownWeapon()
- {
- HandleFinishedFiring();
- Super.PutDownWeapon();
- }
- // Llamado cuando se deja de "disparar". Se llama si RefireCheckTimer determina que no hay que seguir atacando.
- simulated function HandleFinishedFiring()
- {
- if (KHRPawn(Owner).MeleeAnimNode.GetCustomAnimNodeSeq() != None)
- { // Se activa un Timer que reseteara el sistema de Melee cuando termine la animacion actual
- SetTimer(KHRPawn(Owner).MeleeAnimNode.GetCustomAnimNodeSeq().GetTimeLeft(), false, nameof(ResetMelee));
- }
- // Se reactiva el movimiento del Pawn
- KHRPlayerController(Pawn(Owner).Controller).SetRotationOnly(false);
- Super.HandleFinishedFiring();
- }
- // Se llama cuando la animacion de melee concluye. Resetea el sistema para que las animaciones comiencen desde la primera.
- function ResetMelee()
- {
- // Se resetea el combo
- currentSwing = 0;
- }
- // Efectos de ataque
- function SpawnSwingEffects()
- {
- // Sonido de impacto
- if (SwingSound != None)
- {
- PlaySound(SwingSound, true);
- }
- }
- ////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////
- class KHRPawn extends Pawn;
- /******************************************************************************
- Player Properties
- ******************************************************************************/
- var() int HP;
- var() int totalHP;
- var() int MP;
- var() int totalMP;
- var DynamicLightEnvironmentComponent LightEnvironment;
- /******************************************************************************
- Camera Properties
- ******************************************************************************/
- var float CameraScale; // Multiplicador de la distancia por defecto
- var float CurrentCameraScale; // Se usa para interpolar entre distintos CameraScales
- var float CameraZOffset; // Usado para interpolar el offset en z de la cámara
- var vector CamOffset; // Offset de la cámara en tercera persona
- /******************************************************************************
- Animation Properties
- ******************************************************************************/
- var AnimNodeSlot MeleeAnimNode;
- simulated event PostInitAnimTree(SkeletalMeshComponent SkelComp)
- {
- // Se busca la referencia del nodo de animaciones melee
- MeleeAnimNode = AnimNodeSlot(SkelComp.FindAnimNode('MeleeAnim'));
- }
- // Sobreescribe una función para que se vea al pawn por defecto
- // Llama a la Camara cuando este actor se convierte en su ViewTarget
- simulated event BecomeViewTarget( PlayerController PC )
- {
- local UTPlayerController UTPC;
- // Por defecto esta llamada pone los brazos al Pawn y el arma inicial (y otras cosas)
- Super.BecomeViewTarget(PC);
- if (LocalPlayer(PC.Player) != None)
- {
- UTPC = UTPlayerController(PC);
- if (UTPC != None)
- {
- // Activa la vista trasera (Poner la camara en tercera persona y hace desaparecer brazos y armas de primera persona
- UTPC.SetBehindView(true);
- // Esto no es necesario
- //SetMeshVisibility(UTPC.bBehindView);
- }
- }
- }
- // Función que calcula la posición de la cámara
- // Es un ripoff de la función CalcThirdPersonCam de UTPawn, quitando los casos de DebugCam o cuado se gana la partida
- simulated function bool CalcCamera( float fDeltaTime, out vector out_CamLoc,
- out rotator out_CamRot, out float out_FOV )
- {
- local vector CamStart, HitLocation, HitNormal, CamDirX, CamDirY, CamDirZ, CurrentCamOffset;
- local float DesiredCameraZOffset;
- // El punto inicial de la cámara es la posición del Pawn
- CamStart = Location;
- CurrentCamOffset = CamOffset;
- // Si está vivo pone un offset en Z (hacia arriba) del alto del mesh * 1.2
- DesiredCameraZOffset = (Health > 0) ? 1.0 * GetCollisionHeight() + Mesh.Translation.Z : 0.f;
- // Hace una interpolación si el tiempo entre frames es suficientemente pequeño (Se veria si cambiara el offset en Z)
- CameraZOffset = (fDeltaTime < 0.2) ? DesiredCameraZOffset * 5 * fDeltaTime + (1 - 5*fDeltaTime) * CameraZOffset : DesiredCameraZOffset;
- if ( Health <= 0 )
- {
- CurrentCamOffset = vect(0,0,0);
- CurrentCamOffset.X = GetCollisionRadius();
- // adjust camera position to make sure it's not clipping into world
- // @todo fixmesteve. Note that you can still get clipping if FindSpot fails (happens rarely)
- FindSpot(GetCollisionExtent(),CamStart);
- }
- // Se suma a la posición inicial el offset de Z
- CamStart.Z += CameraZOffset;
- // Se extraen los ejes de la rotación de la cámara
- GetAxes(out_CamRot, CamDirX, CamDirY, CamDirZ);
- // Escala de la camara (zoom)
- CamDirX *= CurrentCameraScale;
- // Se interpola la escala de la cámara suavemente (lo que sería el zoom)
- if (CurrentCameraScale < CameraScale)
- {
- CurrentCameraScale = FMin(CameraScale, CurrentCameraScale + 1 * FMax(CameraScale - CurrentCameraScale, 0.3)*fDeltaTime);
- }
- else if (CurrentCameraScale > CameraScale)
- {
- CurrentCameraScale = FMax(CameraScale, CurrentCameraScale - 1 * FMax(CameraScale - CurrentCameraScale, 0.3)*fDeltaTime);
- }
- // No parece que entre aquí nunca
- if (CamDirX.Z > GetCollisionHeight())
- {
- CamDirX *= square(cos(out_CamRot.Pitch * 0.0000958738)); // 0.0000958738 = 2*PI/65536
- }
- // Posición final de la cámara
- out_CamLoc = CamStart - CamDirX*CurrentCamOffset.X + CurrentCamOffset.Y*CamDirY + CurrentCamOffset.Z*CamDirZ;
- // Se traza un rayo para calcular posibles colisiones con la geometría
- if (Trace(HitLocation, HitNormal, out_CamLoc, CamStart, false, vect(12,12,12)) != None)
- {
- out_CamLoc = HitLocation;
- }
- return true;
- }
- // Sobreescribe la funcion de Pawn
- function AddDefaultInventory()
- {
- // Se le da al Pawn el arma al comenzar
- InvManager.CreateInventory(class'KHR.KHRKingdomKey');
- InvManager.CreateInventory(class'KHR.KHRRulerOfDarkness');
- }
- // Cambio de arma, llamado desde PFMPlayerController
- simulated function SwitchWeapon(byte NewGroup)
- {
- if (KHRInventory(InvManager) != None)
- {
- // Se le indica al Manager del Inventario que cambie de arma
- KHRInventory(InvManager).SwitchWeapon(NewGroup);
- }
- }
- defaultproperties
- {
- HP = 100;
- totalHP = 100;
- MP = 60;
- totalMP = 60;
- GroundSpeed = 300;
- AirSpeed = 200;
- InventoryManagerClass=class'KHR.KHRInventory'
- // Propiedades de cámara
- CameraScale=40.0
- CurrentCameraScale=0.0
- CamOffset=(X=5.0,Y=0.0,Z=25.0)
- // Light Enviroment
- Begin Object Class=DynamicLightEnvironmentComponent Name=MyLightEnvironment
- bCastShadows=true
- bShadowFromEnvironment=true
- bSynthesizeSHLight=TRUE
- bIsCharacterLightEnvironment=TRUE
- MinTimeBetweenFullUpdates=0.1
- End Object
- Components.Add(MyLightEnvironment)
- LightEnvironment=MyLightEnvironment
- // Pawn Character //
- Begin Object Class=SkeletalMeshComponent Name=TestSkeletalMesh
- CastShadow=true
- bOwnerNoSee=false
- bCastDynamicShadow=true
- LightEnvironment=MyLightEnvironment
- LightingChannels=(Dynamic=true,Static=true)
- BlockRigidBody=true;
- CollideActors=true;
- BlockZeroExtent=true;
- SkeletalMesh=SkeletalMesh'PC.Mesh.p01zz00'
- AnimSets(0)=AnimSet'PC.Animations.p01zz00_mset'
- AnimTreeTemplate=AnimTree'PC.Animations.p01zz00_animtree'
- End Object
- //Set up collision cylinder. //
- Mesh=TestSkeletalMesh;
- Components.Add(TestSkeletalMesh);
- CollisionType=COLLIDE_BlockAll
- Begin Object Name=CollisionCylinder
- CollisionRadius=+0021.000000
- CollisionHeight=+0044.000000
- Translation=(Z=47)
- End Object
- CylinderComponent=CollisionCylinder
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement