2018-03-29 17:01:57 -04:00
2019-07-07 20:56:15 +00:00
# include <StdAfx.h>
2018-03-29 17:01:57 -04:00
# include "WeenieObject.h"
# include "Scroll.h"
# include "Player.h"
CScrollWeenie : : CScrollWeenie ( )
{
SetName ( " Scroll " ) ;
m_Qualities . m_WeenieType = Scroll_WeenieType ;
}
CScrollWeenie : : ~ CScrollWeenie ( )
{
}
void CScrollWeenie : : ApplyQualityOverrides ( )
{
}
const CSpellBase * CScrollWeenie : : GetSpellBase ( )
{
2019-07-07 20:56:15 +00:00
uint32_t spell_id = 0 ;
2018-05-21 23:20:21 +01:00
2018-05-22 00:06:53 +01:00
2018-03-29 17:01:57 -04:00
if ( m_Qualities . InqDataID ( SPELL_DID , spell_id ) )
{
return MagicSystem : : GetSpellTable ( ) - > GetSpellBase ( spell_id ) ;
}
return NULL ;
}
2018-07-12 14:41:21 -07:00
int CScrollWeenie : : Use ( CPlayerWeenie * player )
2018-03-29 17:01:57 -04:00
{
const CSpellBase * spell = GetSpellBase ( ) ;
if ( ! spell )
{
player - > SendText ( " This scroll doesn't have a spell? " , LTT_DEFAULT ) ;
player - > NotifyInventoryFailedEvent ( GetID ( ) , WERROR_NONE ) ;
player - > NotifyUseDone ( ) ;
return WERROR_NONE ;
}
//You must have a certain skill level in the spell skill of the spell you wish to learn. The required skill levels are the following:
//Level 2 : 0 skill
//Level 3 : 50 skill
//Level 4 : 100 skill
//Level 5 : 150 skill
//Level 6 : 200 skill
//Levels 1 and 7 spells can be learned by anyone, regardless if they have the school trained or not.
bool alwaysSucceed = false ;
if ( spell - > _power < 50 | | spell - > _power > = 300 )
alwaysSucceed = true ;
2019-07-07 20:56:15 +00:00
uint32_t magicSkill = 0 ;
2018-03-29 17:01:57 -04:00
if ( ! alwaysSucceed )
{
2018-06-14 19:03:08 -07:00
if ( ! player - > InqSkill ( spell - > InqSkillForSpell ( ) , magicSkill , FALSE ) | | ! magicSkill )
2018-03-29 17:01:57 -04:00
{
player - > SendText ( csprintf ( " You are not trained in %s! " , CachedSkillTable - > GetSkillName ( spell - > InqSkillForSpell ( ) ) . c_str ( ) ) , LTT_DEFAULT ) ;
player - > NotifyInventoryFailedEvent ( GetID ( ) , WERROR_SKILL_TOO_LOW ) ;
player - > NotifyUseDone ( ) ;
return WERROR_NONE ;
}
else if ( magicSkill < spell - > _power - 50 )
{
player - > SendText ( csprintf ( " You are not skilled enough in %s to learn this spell. " , CachedSkillTable - > GetSkillName ( spell - > InqSkillForSpell ( ) ) . c_str ( ) ) , LTT_DEFAULT ) ;
player - > NotifyInventoryFailedEvent ( GetID ( ) , WERROR_SKILL_TOO_LOW ) ;
player - > NotifyUseDone ( ) ;
return WERROR_NONE ;
}
}
if ( ! player - > FindContainedItem ( GetID ( ) ) )
{
player - > NotifyInventoryFailedEvent ( GetID ( ) , WERROR_OBJECT_GONE ) ;
player - > NotifyUseDone ( ) ;
return WERROR_NONE ;
}
CScrollUseEvent * useEvent = new CScrollUseEvent ;
useEvent - > _target_id = GetID ( ) ;
player - > ExecuteUseEvent ( useEvent ) ;
return WERROR_NONE ;
}
void CScrollUseEvent : : OnReadyToUse ( )
{
ExecuteUseAnimation ( Motion_Reading ) ;
}
2019-07-07 20:56:15 +00:00
void CScrollUseEvent : : OnUseAnimSuccess ( uint32_t motion )
2018-03-29 17:01:57 -04:00
{
2018-07-12 14:41:21 -07:00
CWeenieObject * target = GetTarget ( ) ;
2018-03-29 17:01:57 -04:00
if ( target )
{
2018-07-12 14:41:21 -07:00
if ( _weenie - > LearnSpell ( target - > InqDIDQuality ( SPELL_DID , 0 ) , true ) )
2018-03-29 17:01:57 -04:00
{
// destroy it if the spell was learned
2018-07-12 14:41:21 -07:00
target - > ReleaseFromAnyWeenieParent ( ) ;
_weenie - > NotifyContainedItemRemoved ( target - > GetID ( ) ) ;
2018-03-29 17:01:57 -04:00
2018-07-12 14:41:21 -07:00
target - > MarkForDestroy ( ) ;
2018-03-29 17:01:57 -04:00
}
}
2018-07-12 14:41:21 -07:00
_weenie - > DoForcedStopCompletely ( ) ;
2018-03-29 17:01:57 -04:00
Done ( ) ;
}